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

Parameters:

  • qualified_name (String)

    Element name with prefix

  • use_prefix (String, nil)

    Prefix for this element

  • hoisted_declarations (Hash<String, String>) (defaults to: {})

    xmlns attributes to declare here

  • needs_xmlns_blank (Boolean) (defaults to: false)

    Whether to add xmlns=“” (W3C compliance)

  • schema_location_attr (Hash, nil) (defaults to: nil)

    Schema location attribute to emit



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)

Returns Attribute decisions (matched by index to XmlDataModel).

Returns:

  • (Array<AttributeNode>)

    Attribute decisions (matched by index to XmlDataModel)



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

def attribute_nodes
  @attribute_nodes
end

#element_nodesArray<ElementNode> (readonly)

Returns Child element decisions (matched by index to XmlDataModel).

Returns:

  • (Array<ElementNode>)

    Child element decisions (matched by index to XmlDataModel)



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)

Returns xmlns declarations to emit at this element Keys: “xmlns” or “xmlns:prefix” Values: namespace URIs.

Returns:

  • (Hash<String, String>)

    xmlns declarations to emit at this element Keys: “xmlns” or “xmlns:prefix” Values: namespace URIs



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

def hoisted_declarations
  @hoisted_declarations
end

#needs_xmlns_blankBoolean (readonly)

Returns Whether this element needs xmlns=“” declaration (W3C compliance) True when element is in blank namespace AND parent uses default format.

Returns:

  • (Boolean)

    Whether this element needs xmlns=“” declaration (W3C compliance) True when element is in blank namespace AND parent uses default format



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)

Returns Element name with prefix (e.g., “prefix:element” or “element”).

Returns:

  • (String)

    Element name with prefix (e.g., “prefix:element” or “element”)



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

def qualified_name
  @qualified_name
end

#schema_location_attrHash? (readonly)

Returns Schema location attribute to emit (key: attr name, value) e.g., { “xsi:schemaLocation” => “uri1 loc1 uri2 loc2” }.

Returns:

  • (Hash, nil)

    Schema location attribute to emit (key: attr name, value) e.g., { “xsi:schemaLocation” => “uri1 loc1 uri2 loc2” }



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)

Returns Prefix to use for this element (nil for default format).

Returns:

  • (String, nil)

    Prefix to use for this element (nil for default format)



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

Parameters:

Returns:



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

Parameters:

Returns:



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

Returns:

  • (Boolean)

    true if no prefix (default 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

Returns:

  • (Boolean)

    true if prefix present



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

def uses_prefix_format?
  !use_prefix.nil?
end