Class: Canon::Xml::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/xml/node.rb

Overview

Base class for all XPath data model nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



9
10
11
12
# File 'lib/canon/xml/node.rb', line 9

def initialize
  @parent = nil
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/canon/xml/node.rb', line 7

def children
  @children
end

#parentObject

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



14
15
16
17
# File 'lib/canon/xml/node.rb', line 14

def add_child(child)
  child.parent = self
  @children << child
end

#in_node_set=(value) ⇒ Object



23
24
25
# File 'lib/canon/xml/node.rb', line 23

def in_node_set=(value)
  @in_node_set = value
end

#in_node_set?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/canon/xml/node.rb', line 19

def in_node_set?
  instance_variable_defined?(:@in_node_set) ? @in_node_set : true
end

#parse_errorsArray<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.

Returns:

  • (Array<String>)

    Parse errors as strings (empty by default)



34
35
36
# File 'lib/canon/xml/node.rb', line 34

def parse_errors
  @parse_errors || []
end

#parse_errors=(value) ⇒ Object



38
39
40
# File 'lib/canon/xml/node.rb', line 38

def parse_errors=(value)
  @parse_errors = Array(value)
end

#text_contentObject

Return the text content of this node and all descendants. ElementNode concatenates children’s text_content; other nodes (TextNode, CommentNode, etc.) return their value.



45
46
47
# File 'lib/canon/xml/node.rb', line 45

def text_content
  children.map(&:text_content).join
end