5

I'm working with XML::LibXML in Perl.

Say I have two $element references gotten by different (opaque) XPath queries.

(How) can I determine, if the two $element (Node) refs are the same element in the document tree?

Comparing $el1 == $el2doesn't always work as far as I could tell.

Zaid
  • 36,680
  • 16
  • 86
  • 155
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
  • 1
    It's worth mentioning that `==` doesn't ever work. It's a numeric comparison and there is, as far as `ack` says, no overloading of the operator in the library to check object equality. It might appear to work b/c strings are treated as `0` in perl in numeric context, eg: `perl -le 'print "OK" if "this" == "that"'` --> OK – Ashley Aug 26 '11 at 20:49

1 Answers1

5

It's in the XML::LibXML::Node documentation:


isSameNode

$bool = $node->isSameNode( $other_node );

returns TRUE (1) if the given nodes refer to the same node structure, otherwise FALSE (0) is returned.

Zaid
  • 36,680
  • 16
  • 86
  • 155