[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-xml
Subject:    Re: XML::XPath weirdness
From:       Michel Rodriguez <mirod () xmltwig ! com>
Date:       2004-05-18 6:24:11
Message-ID: Pine.LNX.4.58.0405180202070.13086 () mirlin ! xmltwig ! com
[Download RAW message or body]

On Mon, 17 May 2004, Matt Sergeant wrote:

> On 17 May 2004, at 16:12, Michel Rodriguez wrote:
> 
> > find( '/root/daughter[@id<"2"]'):
> > to_number not available for node XML::XPath::Node::Attribute
> >   node daughter [1]
> >   node daughter [2]
> > find( '/root/daughter[@id<2]'):
> >   node daughter [1]
> >   node daughter [2]
> >
> > I would have thought that an id of 2 would not match @id<2 (the 
> > attribute
> > name is irrelevant here, I have tested it also with an other name).
> 
> I *think* what is happening here is you're getting the effect of 
> position() < 2. But it's hard to say without trying to run the code 
> under a debugger (which I haven't had time to do right now).

I am looking at the code, quite puzzled.

Just a few comments: 

- the code goes through the op_gt sub, so it is really testing the values
and not the position (checked also by changing the attribute values, see 
code below)

- the same code works with XML::LibXML, and from my reading of the code it
should also work in XML::XPath, so I don't think I should have to use
number().

Updated example, with comparison with XML::LibXML:

#!/usr/bin/perl -w
use strict; 
use XML::XPath;
use XML::LibXML;

my $xml='<root><daughter att="3"/><daughter att="4"/><daughter 
att="5"/></root>';
my @queries= ( '/root/daughter[@att<"4"]', '/root/daughter[@att<4]', 
'/root/daughter[@att>4]');

print "XML::XPath:\n";
my $xp = XML::XPath->new( xml => $xml);
foreach my $path ( @queries) 
  { print "find( '$path'):\n";
    my $nodeset= $xp->find( $path);
    foreach my $node ($nodeset->get_nodelist)
      { print "  node ", $node->getName, " [", $node->getAttribute( 
'att'), "]\n"; }
  }

print "XML::LibXML:\n";
my $p= XML::LibXML->new;
my $doc= $p->parse_string( $xml);
foreach my $path ( @queries) 
  { print "find( '$path'):\n";
    my @nodes= $doc->findnodes( $path);
    foreach my $node (@nodes)
      { print "  node ", $node->getName, " [", $node->getAttribute( 
'att'), "]\n"; }
  }


--
Michel Rodriguez
Perl &amp; XML
http://www.xmltwig.com
_______________________________________________
Perl-XML mailing list
Perl-XML@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic