comparing xml

P

Phlip

ara.t.howard said:
this is a rough start

http://gist.github.com/83721

care to improve?

Use LibXML-Ruby, Nokogiri, or REXML, read both documents, and convert them to DOMs.

Recursively compare each node, and all its children, to the matching node in the
other document, and fault if anythings out of tolerance.
 
A

ara.t.howard

Use LibXML-Ruby, Nokogiri, or REXML, read both documents, and
convert them to DOMs.

Recursively compare each node, and all its children, to the matching
node in the other document, and fault if anythings out of tolerance.



err - that is precisely what that code is doing?


a @ http://codeforpeople.com/
 
A

ara.t.howard

I should have explored that. Isn't the code simply printing out both
XMLs, with consistent blanks and indenting, and then comparing their
strings for pure equality?

it *is* comparing strings, but strings built up inside rexml using the
approach you outlined.

If so, would that break over details like attributes out of order?


ah - good catch - i'll check on that. my alternate approach,
comparing xmlsimple data structures will not, i believe, suffer from
that, but i wanted to avoid a dependancy.

i'll check and report back

cheers.

a @ http://codeforpeople.com/
 
P

Phlip

If so, would that break over details like attributes out of order?
ah - good catch - i'll check on that. my alternate approach,
comparing xmlsimple data structures will not, i believe, suffer from
that, but i wanted to avoid a dependancy.

I caught it because I just recently solved a subset of your problem.
assert_xhtml uses Nokogiri to match a subset of HTML within a page. The code is
too weird for you to use, but I indeed had to defeat all the issues you will
encounter!
 
A

ara.t.howard

What about excess spaces in attributes? And what about class='foo
bar' matching class='bar foo'? (Feel free to ignore them!..)


latest version handles the first and i'm ok with the later. feeling
like this is reasonably complete now. crazy none of the ruby xml libs
offer a good doc==other.

cheers.

a @ http://codeforpeople.com/
 
P

Phlip

ara.t.howard said:
latest version handles the first and i'm ok with the later. feeling
like this is reasonably complete now. crazy none of the ruby xml libs
offer a good doc==other.

That is _supposed_ to be XSLT's space. Don't hold your breath. I'm beginning to
suspect XSLT just might be a mission-statement without a company for it to
guide! (-:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top