Hi NGLENN,
On Tue Jul 30 01:40:47 2013, NGLENN wrote:
Show quoted text> I realized that dereferencing the node works (since it's a blessed
> integer). I noticed in the source (line 1252 of LibXML.pm) that numify
> (0+) is overloaded for nodes, but it returns the reference address. I
> think it could be really useful if instead it returned ${$self}. Then
> to get a unique ID for hashes or whatever you'd just have to numify
> the node. I don't know if current numification behavior has any
> specifically defined behavior, but using ${$self} would give $self-
> >isSameNode($onode) iff 0+$self == 0+$self, which would be useful.
>
> use XML::LibXML;
> use Test::More tests => 3;
> my $parser = XML::LibXML->new();
> my $html_doc = $parser->load_xml(string =>
> '<xml><child></child></xml>');
> my @first_children = $html_doc->documentElement->childNodes;
> my @second_children = $html_doc->documentElement->childNodes;
> ok($first_children[0] == $second_children[0], 'not sure what's being
> compared here but it passes');
> ok(0+$first_children[0] != 0+$second_children[0], 'two separate
> objects with different addresses');
> ok(${$first_children[0]} == ${$second_children[0]}, '... with the same
> underlying integer');
>
Well, first of all I suggest providing an API method for it instead of relying on ${$self} which is more subject to change and be broken. If you're interested, you can send me a pull request for that here:
https://bitbucket.org/shlomif/perl-xml-libxml . Something else other people wanted was to be able attach some data on each node via the libxml2 mechanism, or perhaps even a hash of key/string-value pairs. See:
http://code.activestate.com/lists/perl-xml/8953/
Will that help?
Regards,
-- Shlomi Fish
Show quoted text> It may be that you'd rather use just do the dereference thing, but
> whatever the solution, documentation is needed.
>
>
> > ID. So I tried just doing 0+$node, but that didn't work right