On Jul 8, 2:37 pm, Charlie Savage <[EMAIL PROTECTED]> wrote:
> Trans wrote:
>
> > On Jul 8, 12:04 pm, Charlie Savage <[EMAIL PROTECTED]> wrote:
> >>> Hmmm... How does the C library itself handle comparison?
> >> Well, in C the == is identity (comparing pointer addresses).  libxml
> >> does not provide an equality method that I see.
>
> > So there is no way to compare on content, only identity.
>
> Well, its easy enough:
>
> if node1.to_s == node2.to_s
>
> Or
>
> if node1.content == node2.content
>
> to_s is like outerHTML and content is innerHTML (sort of).
>
> But is that
>
> > good for Ruby too? I wonder how changing #== to identity might effect
> > current users?
>
> Best guess it gives them a nice performance boost, since I'm not seeing
> how comparing on content is useful
>
> Even so, I agree that comparing raw xml strings doesn't
>
> > makes sense, but comparing equivalence, as opposed to identity, can be
> > useful, ie. same tag names, same attributes (irregardless of order)
> > and same data.
>
> See above.

Not the same thing. Comparing raw XML string is overly strict. For
example I would expect the following two snips to be "equal":

  <root><foo bar="10" baz="20">Hi</foo></root

and

  <root>
    <foo baz="20" bar="10">
      Hi
    </foo>
  </root>

These would not be equal by string comparison b/c the attribute bar
and baz are not in the same order (to say nothing of white space).

> Otherwise it would seem like we are suggesting that XML
>
> > nodes should be immutable.
>
> Hmm, why do you say that?

If equality is identity, then any node with the same content as
another may as well be the same node. Just like Ruby symbols.

T.
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to