Skip Menu |

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

Report information
The Basics
Id: 18970
Status: rejected
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: jeunice [...] illuminata.com
Cc:
AdminCc:

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



Subject: Findnodes() searches entire document, even when run on a twig
XML::Twig 3.23 doesn't seem to properly limit its findnodes() operation to a given twig. Either that, or I've badly misunderstood findnodes(). Enclosed script reports that there are 4 spans in every section of a document, while in fact there are 1, 2, and 1 respectively. I rate this a critical defect because I can no longer trust the operation of the key findnodes() routine.
Subject: xttest.pl
# Script that shows that either (i) XML::Twig 3.23 doesn't properly limit # its findnodes() operation to a given twig, or that (ii) I have misread # the findnodes() documentation and/or misunderstood its operation. # This script reports that there are 4 spans in every div[@class='section'] # while in fact there are 1, 2, and 1 respectively. Somehow, findnodes() # is searching the entire XML document, not just its respective twig. use XML::Twig; # use XML::Twig::XPath; # even if uncommented, does not seem to change the results use strict; my $xml = <<XML; <container> This is some text. <div id="first" class='section'>Text and <span class="one">some spanned text</span>, OK?</div> <div id="second" class='section'>Some text more text <span class="one">a span</span> and <span class="one">another span</span></div> <div id="third" class='section'>Some text <span class="one">and a span</span></div> Hey, more text! </container> XML my $t = XML::Twig->new(); $t->parse($xml); foreach (qw/first second third/) { my @divs = $t->findnodes("//div[\@id='$_']"); my $d = shift @divs; my @spans = $d->findnodes("//span"); print "findnodes() finds ", scalar(@spans), " spans in $_ DIV, yet the DIV's contents are:\n"; print "\t", $d->sprint, "\n\n"; }
Subject: Re: [rt.cpan.org #18970] Findnodes() searches entire document, even when run on a twig
Date: Fri, 28 Apr 2006 18:33:28 +0200
To: bug-XML-Twig [...] rt.cpan.org
From: Michel Rodriguez <mirod [...] xmltwig.com>
Guest via RT wrote: Show quoted text
> XML::Twig 3.23 doesn't seem to properly limit its findnodes() operation > to a given twig. Either that, or I've badly misunderstood findnodes().
I am afraid (Ok, I am actually happy ;--) that you have misread the XPath spec. '//span' finds spans in all of the document, no matter where you start from, that's what the initial // means. What you need is './/span', which will get you all the span descendants of the current node. -- Michel Rodriguez Perl &amp; XML xmltwig.com
Subject: RE: [rt.cpan.org #18970] Findnodes() searches entire document, even when run on a twig
Date: Fri, 28 Apr 2006 12:54:15 -0400
To: <bug-XML-Twig [...] rt.cpan.org>
From: "Jonathan Eunice" <jeunice [...] illuminata.com>
Ah...then my misunderstanding. I agree...that is very good news! I understood the 'entire document' of a given twig element to be its local subtree, rather than the full document. Not sure why I made that assumption here, which I would not make in an XSLT context...but I did. It actually works just as well in many contexts. But not on more varied documents! Might be worth a quick note in the XML::Twig::Elt::findnodes() document section, if only to keep others from making/reporting the same screwup. Thanks for the quick response. ;-) Show quoted text
-----Original Message----- From: mirod@xmltwig.com via RT [mailto:bug-XML-Twig@rt.cpan.org] Sent: Friday, April 28, 2006 12:37 PM To: Jonathan Eunice Subject: Re: [rt.cpan.org #18970] Findnodes() searches entire document, even when run on a twig <URL: http://rt.cpan.org/Ticket/Display.html?id=18970 > Guest via RT wrote:
> XML::Twig 3.23 doesn't seem to properly limit its findnodes() > operation to a given twig. Either that, or I've badly misunderstood
findnodes(). I am afraid (Ok, I am actually happy ;--) that you have misread the XPath spec. '//span' finds spans in all of the document, no matter where you start from, that's what the initial // means. What you need is './/span', which will get you all the span descendants of the current node. -- Michel Rodriguez Perl &amp; XML xmltwig.com
Subject: Re: [rt.cpan.org #18970] Findnodes() searches entire document, even when run on a twig
Date: Fri, 28 Apr 2006 18:57:43 +0200
To: bug-XML-Twig [...] rt.cpan.org
From: Michel Rodriguez <mirod [...] xmltwig.com>
jeunice@illuminata.com via RT wrote: Show quoted text
> Queue: XML-Twig > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=18970 > > > Ah...then my misunderstanding. I agree...that is very good news! > > I understood the 'entire document' of a given twig element to be its > local subtree, rather than the full document. Not sure why I made that > assumption here, which I would not make in an XSLT context...but I did. > It actually works just as well in many contexts. But not on more varied > documents! > > Might be worth a quick note in the XML::Twig::Elt::findnodes() document > section, if only to keep others from making/reporting the same screwup.
I was about to add a line about this, but somewhere, deep in the docs for findnodes (for an element) is the following line: //para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node Which I think pretty much describes the situation (and is an excerpt from the XPath recomendation IIRC) -- Michel Rodriguez Perl &amp; XML xmltwig.com