Class: Moxml::Document
- Inherits:
-
Node
- Object
- Node
- Moxml::Document
show all
- Defined in:
- lib/moxml/document.rb
Constant Summary
Constants inherited
from Node
Node::TYPES
Instance Attribute Summary
Attributes inherited from Node
#context, #native
Instance Method Summary
collapse
Methods inherited from Node
#==, #add_next_sibling, #add_previous_sibling, #children, #document, #initialize, #next_sibling, #parent, #previous_sibling, #remove, #replace, #to_xml, wrap
Methods included from XmlUtils
#encode_entities, #normalize_xml_value, #validate_comment_content, #validate_declaration_encoding, #validate_declaration_standalone, #validate_declaration_version, #validate_element_name, #validate_pi_target, #validate_prefix, #validate_uri
Constructor Details
This class inherits a constructor from Moxml::Node
Instance Method Details
#add_child(node) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/moxml/document.rb', line 59
def add_child(node)
node = prepare_node(node)
if node.is_a?(Declaration)
if children.empty?
adapter.add_child(@native, node.native)
else
adapter.add_previous_sibling(adapter.children(@native).first, node.native)
end
elsif root && !node.is_a?(ProcessingInstruction) && !node.is_a?(Comment)
raise Error, "Document already has a root element"
else
adapter.add_child(@native, node.native)
end
self
end
|
#at_xpath(expression, namespaces = nil) ⇒ Object
81
82
83
84
85
|
# File 'lib/moxml/document.rb', line 81
def at_xpath(expression, namespaces = nil)
if (native_node = adapter.at_xpath(@native, expression, namespaces))
Node.wrap(native_node, context)
end
end
|
#create_cdata(content) ⇒ Object
32
33
34
|
# File 'lib/moxml/document.rb', line 32
def create_cdata(content)
Cdata.new(adapter.create_cdata(content), context)
end
|
36
37
38
|
# File 'lib/moxml/document.rb', line 36
def (content)
Comment.new(adapter.(content), context)
end
|
#create_declaration(version = "1.0", encoding = "UTF-8", standalone = nil) ⇒ Object
54
55
56
57
|
# File 'lib/moxml/document.rb', line 54
def create_declaration(version = "1.0", encoding = "UTF-8", standalone = nil)
decl = adapter.create_declaration(version, encoding, standalone)
Declaration.new(decl, context)
end
|
#create_doctype(name, external_id, system_id) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/moxml/document.rb', line 40
def create_doctype(name, external_id, system_id)
Doctype.new(
adapter.create_doctype(name, external_id, system_id),
context
)
end
|
#create_element(name) ⇒ Object
24
25
26
|
# File 'lib/moxml/document.rb', line 24
def create_element(name)
Element.new(adapter.create_element(name), context)
end
|
#create_processing_instruction(target, content) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/moxml/document.rb', line 47
def create_processing_instruction(target, content)
ProcessingInstruction.new(
adapter.create_processing_instruction(target, content),
context
)
end
|
#create_text(content) ⇒ Object
28
29
30
|
# File 'lib/moxml/document.rb', line 28
def create_text(content)
Text.new(adapter.create_text(content), context)
end
|
#root ⇒ Object
19
20
21
22
|
# File 'lib/moxml/document.rb', line 19
def root
root_element = adapter.root(@native)
root_element ? Element.wrap(root_element, context) : nil
end
|
#root=(element) ⇒ Object
15
16
17
|
# File 'lib/moxml/document.rb', line 15
def root=(element)
adapter.set_root(@native, element.native)
end
|
#xpath(expression, namespaces = nil) ⇒ Object
76
77
78
79
|
# File 'lib/moxml/document.rb', line 76
def xpath(expression, namespaces = nil)
native_nodes = adapter.xpath(@native, expression, namespaces)
NodeSet.new(native_nodes, context)
end
|