Comparing xml


#1

this is a rough start

care to improve?

kind regards.

a @ http://codeforpeople.com/


#2

ara.t.howard wrote:

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.


#3

On Mar 23, 2009, at 1:22 PM, Phlip wrote:

err - that is precisely what that code is doing?

a @ http://codeforpeople.com/


#4

ara.t.howard wrote:

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?

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?

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


#5

On Mar 23, 2009, at 3:42 PM, Phlip wrote:

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/


#6

On Mar 23, 2009, at 5:07 PM, Phlip wrote:

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!

next version is up

http://gist.github.com/83721

a @ http://codeforpeople.com/


#7

ara.t.howard wrote:

On Mar 23, 2009, at 5:07 PM, Phlip wrote:

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!

next version is up

http://gist.github.com/83721

2kewt. Now you are using XmlSimple.==, so it will walk the object model
for you,
recursively. It takes care of the attribute order issue, and you then
only need
to tell XmlSimple to normalize blanks.

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


#8

On Mar 23, 2009, at 6:26 PM, Phlip wrote:

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/


#9

ara.t.howard wrote:

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! (-:


#10

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!


#11

On Mar 23, 2009, at 8:26 PM, Phlip wrote:

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! (-:

that is the one with ‘bacon’ isn’t it?

a @ http://codeforpeople.com/