Project

xml-c14n

0.0
The project is in a healthy, maintained state
Library for XML canonicalization
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

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.