module Rsxml
Constants
- TO_RSXML_OPTS
- TO_XML_OPTS
Attributes
logger[RW]
Public Instance Methods
compare(xml_or_sexp_a, xml_or_sexp_b)
click to toggle source
compare two documents in XML or Rsxml
. returns true
if they are identical, and if not raises ComparisonError
describing where they differ
# File lib/rsxml.rb, line 54 def compare(xml_or_sexp_a, xml_or_sexp_b) sexp_a = xml_or_sexp_a.is_a?(String) ? to_rsxml(xml_or_sexp_a) : xml_or_sexp_a sexp_b = xml_or_sexp_b.is_a?(String) ? to_rsxml(xml_or_sexp_b) : xml_or_sexp_b Sexp.compare(sexp_a, sexp_b) end
log() { |logger| ... }
click to toggle source
# File lib/rsxml.rb, line 19 def log yield(logger) if logger end
to_rsxml(doc, opts={})
click to toggle source
convert an XML string to an Rsxml
s-expression representation
Rsxml.to_rsxml('<Foo foofoo="10"><Bar>barbar</Bar><Baz></Baz></Foo>') => ["Foo", {"foofoo"=>"10"}, ["Bar", "barbar"], ["Baz"]]
if ns_prefixes
is a Hash, then doc
is assumed to be a fragment, and is wrapped in an element with namespace declarations according to ns_prefixes
fragment = '<foo:Foo foo:foofoo="10"><Bar>barbar</Bar><Baz></Baz></Foo>' Rsxml.to_rsxml(fragment, {"foo"=>"http://foo.com/foo", ""=>"http://baz.com/baz"}) => ["foo:Foo", {"foo:foofoo"=>"10", "xmlns:foo"=>"http://foo.com/foo", "xmlns"=>"http://baz.com/baz"}, ["Bar", "barbar"], ["Baz"]]
# File lib/rsxml.rb, line 45 def to_rsxml(doc, opts={}) opts = check_opts(TO_RSXML_OPTS, opts) doc = Xml.wrap_fragment(doc, opts.delete(:ns)) root = Xml.unwrap_fragment(Nokogiri::XML(doc).children.first) Xml.traverse(root, Visitor::BuildRsxmlVisitor.new(opts)).sexp end
to_xml(rsxml, opts={})
click to toggle source
convert an Rsxml
s-expression representation of an XML document to XML
Rsxml.to_xml(["Foo", {"foofoo"=>"10"}, ["Bar", "barbar"] ["Baz"]]) => '<Foo foofoo="10"><Bar>barbar</Bar><Baz></Baz></Foo>'
# File lib/rsxml.rb, line 28 def to_xml(rsxml, opts={}) opts = check_opts(TO_XML_OPTS, opts) Sexp.traverse(rsxml, Visitor::WriteXmlVisitor.new, Visitor::Context.new(opts[:ns])).to_s end