Skip Menu |

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 18319
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: MIROD [...] cpan.org
Requestors: teds [...] intex.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.23
Fixed in: (no value)



Subject: find_nodes() not finding elements
Run the simple perl script with the attached XML file in the same directory. The output shows D:\MyWork\perl_scripts\WishList>perl -w twig.pl New entry - To Die for will look for nodes with att - //Item[@A='To Die for'] Found in archive New entry - To/Die/for will look for nodes with att - //Item[@A='To/Die/for'] Not found in archive My question is why the second entry is NOT found in the archive. It seems to have something to do with the forward slash. Any ideas? Thanks, Ted
Subject: test.xml
<?xml version="1.0" ?> <WishList> <Item A='To Die for'> </Item> <Item A='To/Die/for'> </Item> </WishList>
Subject: twig.pl
use strict; use warnings; use diagnostics; use XML::Twig; my $archive_twig; sub item { my( $t, $item ) = @_; # arguments for all twig_handlers my $a = $item->att('A'); print "\n\nNew entry - $a"; my $xp = sprintf( "//Item[\@A='%s']", $a); print "\nwill look for nodes with att - $xp"; my @elt_array = $archive_twig->findnodes( $xp ); if ( scalar(@elt_array) > 0 ) { print "\nFound in archive"; } else { print "\nNot found in archive"; } } # we will search this twig for elements found from twig $t $archive_twig = XML::Twig->new( keep_encoding => 1 ); $archive_twig->parsefile( ".\\test.xml" ); my $t = XML::Twig->new( twig_handlers => { 'WishList/Item' => \&item }, keep_encoding => 1 ); $t->parsefile( ".\\test.xml" ); exit 0;
Indeed that's a bug in the (quite lame) XPath engine. Using XML::Twig::XPath solves this problem. Is this something you can do? I'll have a look at the XPath engine, but I am not sure it's easily fixable, baring a complete rewrite of the XPath parser. __ mirod
From: teds [...] intex.com
On Thu Mar 23 10:28:19 2006, MIROD wrote: Show quoted text
> Indeed that's a bug in the (quite lame) XPath engine. Using > XML::Twig::XPath solves this problem. Is this something you can do?
I'm more than happy to change things but I'm not quite sure what you mean by "Using XML::Twig::XPath" solves the problem. Is there another function call I should make off of the twig instead of findnodes()? Show quoted text
> > I'll have a look at the XPath engine, but I am not sure it's easily > fixable, baring a complete rewrite of the XPath parser. > __ > mirod
Subject: Re: [rt.cpan.org #18319] find_nodes() not finding elements
Date: Thu, 23 Mar 2006 17:15:22 +0100
To: bug-XML-Twig [...] rt.cpan.org
From: Michel Rodriguez <mirod [...] xmltwig.com>
Guest via RT wrote: Show quoted text
> Queue: XML-Twig > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=18319 > > > On Thu Mar 23 10:28:19 2006, MIROD wrote:
>> Indeed that's a bug in the (quite lame) XPath engine. Using >> XML::Twig::XPath solves this problem. Is this something you can do?
> > I'm more than happy to change things but I'm not quite sure what you > mean by "Using XML::Twig::XPath" solves the problem. Is there > another function call I should make off of the twig instead of > findnodes()?
No, if you use XML::Twig::XPath (you need to install XML::XPath for this), then the findnodes that's used is the one provided by XML::XPath, instead of the regular one. So you should just have to change the use statement. -- Michel Rodriguez Perl &amp; XML xmltwig.com
From: teds [...] intex.com
On Thu Mar 23 11:16:18 2006, mirod@xmltwig.com wrote: Show quoted text
> Guest via RT wrote:
> > Queue: XML-Twig > > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=18319 > > > > > On Thu Mar 23 10:28:19 2006, MIROD wrote:
> >> Indeed that's a bug in the (quite lame) XPath engine. Using > >> XML::Twig::XPath solves this problem. Is this something you can
do? Show quoted text
> > > > I'm more than happy to change things but I'm not quite sure what
you Show quoted text
> > mean by "Using XML::Twig::XPath" solves the problem. Is there > > another function call I should make off of the twig instead of > > findnodes()?
> > No, if you use XML::Twig::XPath (you need to install XML::XPath for > this), then the findnodes that's used is the one provided by
XML::XPath, Show quoted text
> instead of the regular one. So you should just have to change the
use Show quoted text
> statement. > >
I added this line so my perl script now looks as show below. However, the results are still the same. Thanks, Ted use strict; use warnings; use diagnostics; use XML::Twig; use XML::Twig::XPath; # my $archive_twig; sub item { my( $t, $item ) = @_; # arguments for all twig_handlers my $a = $item->att('A'); print "\n\nNew entry - $a"; my $xp = sprintf( "//Item[\@A=\'%s\']", $a); print "\nwill look for nodes with att - $xp"; my @elt_array = $archive_twig->findnodes( $xp ); if ( scalar(@elt_array) > 0 ) { print "\nFound in archive"; } else { print "\nNot found in archive"; } } # we will search this twig for elements found from twig $t $archive_twig = XML::Twig->new( keep_encoding => 1 ); $archive_twig->parsefile( ".\\test.xml" ); my $t = XML::Twig->new( twig_handlers => { 'WishList/Item' => \&item }, keep_encoding => 1 ); $t->parsefile( ".\\test.xml" ); exit 0;
Subject: Re: [rt.cpan.org #18319] find_nodes() not finding elements
Date: Thu, 23 Mar 2006 18:01:31 +0100
To: bug-XML-Twig [...] rt.cpan.org
From: Michel Rodriguez <mirod [...] xmltwig.com>
Guest via RT wrote: Show quoted text
> use XML::Twig; > use XML::Twig::XPath;
just use XML::Twig::XPath, not XML::Twig, it worked for me. -- Michel Rodriguez Perl &amp; XML xmltwig.com
From: teds [...] intex.com
On Thu Mar 23 12:02:03 2006, mirod@xmltwig.com wrote: Show quoted text
> Guest via RT wrote: >
> > use XML::Twig; > > use XML::Twig::XPath;
> > just use XML::Twig::XPath, not XML::Twig, it worked for me. >
Sorry for the hassle but that still didn't work. I currently have 0.01 of XML::Twig::XPath, 3.22 of XML::Twig, 1.13 of XML::XPath with Show quoted text
>perl -v
This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) So you see both entry's as found? Thanks, Ted
From: teds [...] intex.com
On Thu Mar 23 12:29:48 2006, guest wrote: Show quoted text
> On Thu Mar 23 12:02:03 2006, mirod@xmltwig.com wrote:
> > Guest via RT wrote: > >
> > > use XML::Twig; > > > use XML::Twig::XPath;
> > > > just use XML::Twig::XPath, not XML::Twig, it worked for me. > >
> > Sorry for the hassle but that still didn't work. I currently have > 0.01 of XML::Twig::XPath, 3.22 of XML::Twig, 1.13 of XML::XPath > with >
> >perl -v
> > This is perl, v5.8.6 built for MSWin32-x86-multi-thread > (with 3 registered patches, see perl -V for more detail) > > So you see both entry's as found? > > Thanks, > > Ted >
My ignorance, I didn't realize I needed to do a $t = XML::Twig::XPath->new( ); I was still doing a $t = XML::Twig->new( ); Thanks for your help. Ted