XML Unit?

Is there a ruby equivalent of Java’s XML Unit, whereby you can compare two
pieces of XML for structure (regardless of whitespace, formatting, etc.)?

Thanks in advance,

Aidan

Aidan Rogers wrote:

Is there a ruby equivalent of Java’s XML Unit, whereby you can compare two
pieces of XML for structure (regardless of whitespace, formatting, etc.)?

That is a job for XSLT. (I suspect.)

···


Phlip
Test First User Interfaces

Aidan Rogers aidan@yoyo.org wrote in message news:opr40bakg53yuc6c@jem.yoyo.org

Is there a ruby equivalent of Java’s XML Unit, whereby you can compare two
pieces of XML for structure (regardless of whitespace, formatting, etc.)?

Do you just want to test for equality, or are you looking for a
diffing algorithm? When you say “regardless of whitespace”, do you
mean just collapsing whitespace, or just pure whitespace nodes?

ruby -rrexml/document -e '
pref = {:ignore_whitespace_nodes=>:all}
a = REXML::Document.new( "<a>  <b>sean</b>  </a>", pref )
b = REXML::Document.new( "<a><b>sean</b></a>", pref)
puts a.to_s == b.to_s'

=> true

— SER

Quoteing phlip_cpp@yahoo.com, on Thu, Mar 18, 2004 at 08:34:36AM +0900:

Aidan Rogers wrote:

Is there a ruby equivalent of Java’s XML Unit, whereby you can compare two
pieces of XML for structure (regardless of whitespace, formatting, etc.)?

That is a job for XSLT. (I suspect.)

Can you process two documents in parallel with xslt? I don’t think you
can.

I suspect two “pull” parsers running in parallel would be the efficient
way, then you could decide what exactly you mean by “structure”.

Another way would be to “canonicalize” the xml, and them bytewise
compare the pieces.

Sam

Phlip wrote:

Aidan Rogers wrote:

Is there a ruby equivalent of Java’s XML Unit, whereby you can compare two
pieces of XML for structure (regardless of whitespace, formatting, etc.)?

That is a job for XSLT. (I suspect.)

Could be. You might transform the each bit of XML to another,
canonical, string, omitting the content. Then see if they both give the
same string.

There’s no native Ruby XSLT lib, though, if that’s an issue. But it
should be trivial to write a lib that uses the REXML stream parser to
simply pass through the markup structure while swallowing the content.

James