Class: Oga::XML::Document
- Inherits:
-
Object
- Object
- Oga::XML::Document
- Defined in:
- lib/oga/xml/document.rb
Overview
Class used for storing information about an entire XML document. This includes the doctype, XML declaration, child nodes and more.
Instance Attribute Summary collapse
-
#doctype ⇒ Oga::XML::Doctype
The doctype of the document.
-
#type ⇒ Symbol
readonly
The document type, either
:xml
or:html
. - #xml_declaration ⇒ Oga::XML::XmlDeclaration
Instance Method Summary collapse
- #children ⇒ Oga::XML::NodeSet
-
#children=(nodes) ⇒ Object
Sets the child nodes of the document.
- #html? ⇒ TrueClass|FalseClass
-
#initialize(options = {}) ⇒ Document
constructor
A new instance of Document.
-
#inspect ⇒ String
Inspects the document and its child nodes.
- #literal_html_name? ⇒ FalseClass
-
#root_node ⇒ Oga::XML::Document
Returns self.
Methods included from ToXML
Methods included from Traversal
Methods included from Querying
#at_css, #at_xpath, #css, #xpath
Constructor Details
#initialize(options = {}) ⇒ Document
Returns a new instance of Document.
31 32 33 34 35 36 37 |
# File 'lib/oga/xml/document.rb', line 31 def initialize( = {}) @doctype = [:doctype] @xml_declaration = [:xml_declaration] @type = [:type] || :xml self.children = [:children] if [:children] end |
Instance Attribute Details
#doctype ⇒ Oga::XML::Doctype
The doctype of the document.
When parsing a document this attribute will be set automatically if a doctype resides at the root of the document.
16 17 18 |
# File 'lib/oga/xml/document.rb', line 16 def doctype @doctype end |
#type ⇒ Symbol (readonly)
The document type, either :xml
or :html
.
23 24 25 |
# File 'lib/oga/xml/document.rb', line 23 def type @type end |
#xml_declaration ⇒ Oga::XML::XmlDeclaration
19 20 21 |
# File 'lib/oga/xml/document.rb', line 19 def xml_declaration @xml_declaration end |
Instance Method Details
#children ⇒ Oga::XML::NodeSet
40 41 42 |
# File 'lib/oga/xml/document.rb', line 40 def children @children ||= NodeSet.new([], self) end |
#children=(nodes) ⇒ Object
Sets the child nodes of the document.
47 48 49 50 51 52 53 54 55 |
# File 'lib/oga/xml/document.rb', line 47 def children=(nodes) if nodes.is_a?(NodeSet) nodes.owner = self nodes.take_ownership_on_nodes @children = nodes else @children = NodeSet.new(nodes, self) end end |
#html? ⇒ TrueClass|FalseClass
68 69 70 |
# File 'lib/oga/xml/document.rb', line 68 def html? type.equal?(:html) end |
#inspect ⇒ String
Inspects the document and its child nodes. Child nodes are indented for each nesting level.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/oga/xml/document.rb', line 76 def inspect segments = [] [:doctype, :xml_declaration, :children].each do |attr| value = send(attr) if value segments << "#{attr}: #{value.inspect}" end end <<-EOF.strip Document( #{segments.join("\n ")} ) EOF end |
#literal_html_name? ⇒ FalseClass
95 96 97 |
# File 'lib/oga/xml/document.rb', line 95 def literal_html_name? false end |
#root_node ⇒ Oga::XML::Document
Returns self.
This method exists to make this class compatible with Element, which in turn makes it easier to use both in the XPath compiler.
63 64 65 |
# File 'lib/oga/xml/document.rb', line 63 def root_node self end |