Class: Canon::Xml::Node
- Inherits:
-
Object
- Object
- Canon::Xml::Node
- Defined in:
- lib/canon/xml/node.rb
Overview
Base class for all XPath data model nodes
Direct Known Subclasses
Canon::Xml::Nodes::AttributeNode, Canon::Xml::Nodes::CommentNode, Canon::Xml::Nodes::ElementNode, Canon::Xml::Nodes::NamespaceNode, Canon::Xml::Nodes::ProcessingInstructionNode, Canon::Xml::Nodes::RootNode, Canon::Xml::Nodes::TextNode
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #in_node_set=(value) ⇒ Object
- #in_node_set? ⇒ Boolean
-
#initialize ⇒ Node
constructor
A new instance of Node.
-
#parse_errors ⇒ Array<String>
Parse-time errors carried alongside the node tree, captured at parse boundaries (Canon::Xml::DataModel.from_xml, etc.) so the diff report can surface libxml-level FATAL conditions that would otherwise be silently swallowed and produce misleading diffs against a partially-loaded tree.
- #parse_errors=(value) ⇒ Object
-
#text_content ⇒ Object
Return the text content of this node and all descendants.
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
9 10 11 12 13 |
# File 'lib/canon/xml/node.rb', line 9 def initialize @parent = nil @children = [] @in_node_set = true end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/canon/xml/node.rb', line 7 def children @children end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/canon/xml/node.rb', line 7 def parent @parent end |
Instance Method Details
#add_child(child) ⇒ Object
15 16 17 18 |
# File 'lib/canon/xml/node.rb', line 15 def add_child(child) child.parent = self @children << child end |
#in_node_set=(value) ⇒ Object
24 25 26 |
# File 'lib/canon/xml/node.rb', line 24 def in_node_set=(value) @in_node_set = value end |
#in_node_set? ⇒ Boolean
20 21 22 |
# File 'lib/canon/xml/node.rb', line 20 def in_node_set? @in_node_set end |
#parse_errors ⇒ Array<String>
Parse-time errors carried alongside the node tree, captured at parse boundaries (Canon::Xml::DataModel.from_xml, etc.) so the diff report can surface libxml-level FATAL conditions that would otherwise be silently swallowed and produce misleading diffs against a partially-loaded tree. See lutaml/canon#130.
35 36 37 |
# File 'lib/canon/xml/node.rb', line 35 def parse_errors @parse_errors || [] end |
#parse_errors=(value) ⇒ Object
39 40 41 |
# File 'lib/canon/xml/node.rb', line 39 def parse_errors=(value) @parse_errors = Array(value) end |
#text_content ⇒ Object
Return the text content of this node and all descendants. ElementNode concatenates children’s text_content; other nodes (TextNode, CommentNode, etc.) return their value.
46 47 48 |
# File 'lib/canon/xml/node.rb', line 46 def text_content children.map(&:text_content).join end |