Class: Canon::Xml::C14n

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

Overview

XML Canonicalization 1.1 implementation Per W3C Recommendation: www.w3.org/TR/xml-c14n11/

Class Method Summary collapse

Class Method Details

.canonicalize(xml, with_comments: false) ⇒ String

Canonicalize an XML document

Parameters:

  • xml (String)

    XML document as string

  • with_comments (Boolean) (defaults to: false)

    Include comments in canonical form

Returns:

  • (String)

    Canonical form in UTF-8



15
16
17
18
19
20
21
22
# File 'lib/canon/xml/c14n.rb', line 15

def self.canonicalize(xml, with_comments: false)
  # Build XPath data model
  root_node = DataModel.from_xml(xml)

  # Process to canonical form
  processor = Processor.new(with_comments: with_comments)
  processor.process(root_node)
end

.canonicalize_subset(xml, _xpath, with_comments: false) ⇒ String

Canonicalize a document subset (for future implementation)

Parameters:

  • xml (String)

    XML document as string

  • xpath (String)

    XPath expression for subset selection

  • with_comments (Boolean) (defaults to: false)

    Include comments in canonical form

Returns:

  • (String)

    Canonical form in UTF-8



29
30
31
32
33
# File 'lib/canon/xml/c14n.rb', line 29

def self.canonicalize_subset(xml, _xpath, with_comments: false)
  # TODO: Implement XPath-based subset selection
  # For now, just canonicalize the whole document
  canonicalize(xml, with_comments: with_comments)
end