Forum: Ruby comparing xml

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ara H. (Guest)
on 2009-03-23 21:09
(Received via mailing list)
this is a rough start

http://gist.github.com/83721

care to improve?

kind regards.

a @ http://codeforpeople.com/
Phlip (Guest)
on 2009-03-23 21:25
(Received via mailing list)
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.
Ara H. (Guest)
on 2009-03-23 21:31
(Received via mailing list)
On Mar 23, 2009, at 1:22 PM, Phlip wrote:

>
err - that is precisely what that code is doing?


a @ http://codeforpeople.com/
Phlip (Guest)
on 2009-03-23 23:46
(Received via mailing list)
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?
Ara H. (Guest)
on 2009-03-24 00:46
(Received via mailing list)
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/
Phlip (Guest)
on 2009-03-24 01:10
(Received via mailing list)
>> 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!
Ara H. (Guest)
on 2009-03-24 01:17
(Received via mailing list)
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/
Phlip (Guest)
on 2009-03-24 03:09
(Received via mailing list)
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!..)
Ara H. (Guest)
on 2009-03-24 03:09
(Received via mailing list)
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/
Phlip (Guest)
on 2009-03-24 04:30
(Received via mailing list)
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! (-:
Ara H. (Guest)
on 2009-03-24 04:53
(Received via mailing list)
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/
This topic is locked and can not be replied to.