Module: Lutaml::Xml::NamespaceDeclarationBuilder

Defined in:
lib/lutaml/xml/namespace_declaration_builder.rb

Overview

NamespaceDeclarationBuilder - Build xmlns attributes from DeclarationPlan

REFACTORED (Session 176): Builds xmlns strings from NamespaceDeclaration DATA NO MORE reading pre-built xmlns_declaration strings

REFACTORED (Session 182): Added build_all_xmlns_attributes to include Type namespace declarations

CRITICAL ARCHITECTURAL PRINCIPLE: Adapters build XML strings from data Planning produces data, rendering produces XML

PURPOSE: Converts namespace declarations from a DeclarationPlan into xmlns attributes for XML element construction.

USAGE:

attributes = NamespaceDeclarationBuilder.build_all_xmlns_attributes(plan)

Class Method Summary collapse

Class Method Details

.build_all_xmlns_attributes(plan) ⇒ Hash

Build ALL xmlns attributes from plan (regular + Type namespaces)

CRITICAL (Session 197): Type namespaces are now handled by DeclarationPlanner and stored in the plan like any other namespace. No special handling needed. This enforces the “Dumb Adapter” principle - rendering only reads from plan.

Parameters:

Returns:

  • (Hash)

    attributes hash with all xmlns declarations



34
35
36
37
# File 'lib/lutaml/xml/namespace_declaration_builder.rb', line 34

def self.build_all_xmlns_attributes(plan)
  # DUMB ADAPTER: Just build from plan, no decisions
  build_xmlns_attributes(plan)
end

.build_xmlns_attributes(plan) ⇒ Hash

Build xmlns attributes from namespace declarations in plan

Parameters:

Returns:

  • (Hash)

    attributes hash with xmlns declarations



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lutaml/xml/namespace_declaration_builder.rb', line 43

def self.build_xmlns_attributes(plan)
  attributes = {}

  # Read from tree structure
  plan.root_node.hoisted_declarations.each do |key, uri|
    # CRITICAL: Never declare xml namespace - it's implicitly bound
    next if uri == "http://www.w3.org/XML/1998/namespace"

    # Build xmlns attribute based on key type:
    # nil = default namespace (xmlns="uri")
    # String = prefixed namespace (xmlns:prefix="uri")
    if key.nil?
      # Default namespace
      attributes["xmlns"] = uri
    else
      # Prefixed namespace
      attributes["xmlns:#{key}"] = uri
    end
  end

  attributes
end