Class: Moxml::C14n::DataModel

Inherits:
Object
  • Object
show all
Defined in:
lib/moxml/c14n/data_model.rb

Overview

Builds a C14N data model from a Moxml::Node tree (or XML string).

The data model exists because canonicalization needs:

- sorted namespace and attribute axes (spec §2.3, §2.4)
- in_node_set flags for subset canonicalization (spec §3)
- xml:* inheritable attribute resolution

Ported from canon (lutaml/canon) — adapted to build directly from Moxml::Node rather than via a separate Nokogiri pass. Matches canon's document-level node iteration (PIs and comments outside the document root element).

Class Method Summary collapse

Class Method Details

.from_node(moxml_node) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/moxml/c14n/data_model.rb', line 21

def self.from_node(moxml_node)
  return build_from_document(moxml_node) if moxml_node.is_a?(::Moxml::Document)

  root = Nodes::RootNode.new
  root.add_child(build_node(moxml_node))
  root
end

.from_xml(xml_string) ⇒ Object



17
18
19
# File 'lib/moxml/c14n/data_model.rb', line 17

def self.from_xml(xml_string)
  from_node(::Moxml.parse(xml_string))
end

.mark_all(node, value) ⇒ Object



123
124
125
126
# File 'lib/moxml/c14n/data_model.rb', line 123

def self.mark_all(node, value)
  node.in_node_set = value
  node.children.each { |child| mark_all(child, value) }
end

.mark_subset(root_node, matched) ⇒ Object



128
129
130
131
# File 'lib/moxml/c14n/data_model.rb', line 128

def self.mark_subset(root_node, matched)
  matched.each { |node| mark_node_and_descendants(node) }
  root_node.in_node_set = true
end