Skip to content

Ruby library to canonicalize XML (e.g. for comparison)

Notifications You must be signed in to change notification settings

metanorma/xml-c14n

Repository files navigation

XML pretty-print / canonicalizer / RSpec comparator

Purpose

This gem provides Xml::C14n which is a library that uses Nokogiri to pretty-print and provide a canonicalized form of XML (W3C Canonicalized XML) suitable for signing and comparison.

This gem also provides the RSpec matcher be_analogous_with for comparing XML content. The matcher used is from the compare-xml gem.

Usage

require 'xml/c14n'

input = Xml::C14n.format(File.read(xml_raw))
output = Xml::C14n.format(File.read(xml_c14n))

input == output

In RSpecs:

# In spec/spec_helper.rb
require 'xml/c14n'

# In spec/*_spec.rb
it "canonicalizes #{File.basename(f)}" do
  input = Xml::C14n.format(File.read(xml_raw))
  output = Xml::C14n.format(File.read(xml_c14n))

  expect(output).to eq(input)
end

it "checks if analogous with #{File.basename(f)}" do
  input = Xml::C14n.format(File.read(xml_raw))
  output = Xml::C14n.format(File.read(xml_c14n))

  expect(output).to be_analogous_with(input)
end

License

Copyright Ribose.

About

Ruby library to canonicalize XML (e.g. for comparison)

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published