[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

comparing xml

ara.t.howard

3/23/2009 7:06:00 PM


this is a rough start

http://gist.github...

care to improve?

kind regards.

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




10 Answers

Phlip

3/23/2009 7:22:00 PM

0

ara.t.howard wrote:
> this is a rough start
>
> http://gist.github...
>
> 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.t.howard

3/23/2009 7:28:00 PM

0


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

> ara.t.howard wrote:
>> this is a rough start
>> http://gist.github...
>> 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.
>



err - that is precisely what that code is doing?


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Phlip

3/23/2009 9:42:00 PM

0

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.t.howard

3/23/2009 10:42:00 PM

0


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://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Phlip

3/23/2009 11:09:00 PM

0

>> 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.t.howard

3/23/2009 11:14:00 PM

0


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...


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Phlip

3/24/2009 12:27:00 AM

0

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...

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.t.howard

3/24/2009 12:32:00 AM

0


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://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Phlip

3/24/2009 2:28:00 AM

0

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.t.howard

3/24/2009 2:49:00 AM

0


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://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama