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 |
# File 'lib/oga/xml/document.rb', line 47 def children=(nodes) if nodes.is_a?(NodeSet) @children = nodes else @children = NodeSet.new(nodes, self) end end |
#html? ⇒ TrueClass|FalseClass
66 67 68 |
# File 'lib/oga/xml/document.rb', line 66 def html? type.equal?(:html) end |
#inspect ⇒ String
Inspects the document and its child nodes. Child nodes are indented for each nesting level.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/oga/xml/document.rb', line 74 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
93 94 95 |
# File 'lib/oga/xml/document.rb', line 93 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.
61 62 63 |
# File 'lib/oga/xml/document.rb', line 61 def root_node self end |