Class: Lutaml::Xml::DeclarationPlan::ElementNode

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/declaration_plan/element_node.rb

Overview

ElementNode represents namespace decisions for a single XML element in the tree

This is a PURE DATA structure - it stores decisions made by DeclarationPlanner but contains NO decision-making logic itself.

The ElementNode tree is isomorphic to the XmlDataModel tree, allowing adapters to traverse both trees in parallel by index/position.

Examples:

element_node = ElementNode.new(
  qualified_name: "prefix:ElementName",
  use_prefix: "prefix",
  hoisted_declarations: { "xmlns:prefix" => "http://example.com/ns" }
)
element_node.add_attribute_node(attr_node)
element_node.add_element_node(child_node)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qualified_name:, use_prefix:, hoisted_declarations: {}, needs_xmlns_blank: false, schema_location_attr: nil) ⇒ ElementNode

Initialize an element node



56
57
58
59
60
61
62
63
64
65
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 56

def initialize(qualified_name:, use_prefix:,
    hoisted_declarations: {}, needs_xmlns_blank: false, schema_location_attr: nil)
  @qualified_name = qualified_name
  @use_prefix = use_prefix
  @hoisted_declarations = hoisted_declarations
  @attribute_nodes = []
  @element_nodes = []
  @needs_xmlns_blank = needs_xmlns_blank
  @schema_location_attr = schema_location_attr
end

Instance Attribute Details

#attribute_nodesArray<AttributeNode> (readonly)



36
37
38
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 36

def attribute_nodes
  @attribute_nodes
end

#element_nodesArray<ElementNode> (readonly)



39
40
41
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 39

def element_nodes
  @element_nodes
end

#hoisted_declarationsHash<String, String> (readonly)



33
34
35
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 33

def hoisted_declarations
  @hoisted_declarations
end

#needs_xmlns_blankBoolean (readonly)



43
44
45
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 43

def needs_xmlns_blank
  @needs_xmlns_blank
end

#qualified_nameString (readonly)



25
26
27
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 25

def qualified_name
  @qualified_name
end

#schema_location_attrHash? (readonly)



47
48
49
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 47

def schema_location_attr
  @schema_location_attr
end

#use_prefixString? (readonly)



28
29
30
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 28

def use_prefix
  @use_prefix
end

Instance Method Details

#add_attribute_node(node) ⇒ AttributeNode

Add an attribute decision node



71
72
73
74
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 71

def add_attribute_node(node)
  @attribute_nodes << node
  node
end

#add_element_node(node) ⇒ ElementNode

Add a child element decision node



80
81
82
83
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 80

def add_element_node(node)
  @element_nodes << node
  node
end

#uses_default_format?Boolean

Check if this element uses default namespace format



88
89
90
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 88

def uses_default_format?
  use_prefix.nil?
end

#uses_prefix_format?Boolean

Check if this element uses prefix format



95
96
97
# File 'lib/lutaml/xml/declaration_plan/element_node.rb', line 95

def uses_prefix_format?
  !use_prefix.nil?
end