Skip Menu |

This queue is for tickets about the HTML-TreeBuilder-XPath CPAN distribution.

Report information
The Basics
Id: 30792
Status: resolved
Priority: 0/
Queue: HTML-TreeBuilder-XPath

People
Owner: Nobody in particular
Requestors: tokuhirom [...] gmail.com
Cc:
AdminCc:

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



Subject: Cannot use id("Foo")
If use XPath 'id("foo")' then follow error is occurred. Can't locate object method "getElementById" via package "HTML::TreeBuilder::XPath" at /usr/local/share/perl/5.8.8/XML/XPathEngine/Function.pm line 121. please add the method HTML::TreeBuilder::XPath->getElementById. follow is a patch for library and test. __END__ === lib/HTML/TreeBuilder/XPath.pm ================================================================== --- lib/HTML/TreeBuilder/XPath.pm (revision 7244) +++ lib/HTML/TreeBuilder/XPath.pm (local) @@ -11,6 +11,10 @@ use base( 'HTML::TreeBuilder'); +sub getElementById { + my ($self, $id) = @_; + ( $self->findnodes(qq{//*[\@id="$id"]}) )[0]; +} package HTML::TreeBuilder::XPath::Node; === t/HTML-TreeBuilder-XPath.t ================================================================== --- t/HTML-TreeBuilder-XPath.t (revision 7244) +++ t/HTML-TreeBuilder-XPath.t (local) @@ -3,7 +3,7 @@ ######################### -use Test::More tests => 17; +use Test::More tests => 18; BEGIN { use_ok('HTML::TreeBuilder::XPath') }; ######################### @@ -53,6 +53,8 @@ } +is( $html->findvalue('id("foo")/@id'), 'foo', 'id function'); + __END__ /html/body/h1 1 Example header //@id[.="toto"] 2 toto
Subject: Re: [rt.cpan.org #30792] Cannot use id("Foo")
Date: Sat, 17 Nov 2007 12:28:00 +0100
To: bug-HTML-TreeBuilder-XPath [...] rt.cpan.org
From: "Michel Rodriguez" <xmltwig [...] gmail.com>
On 11/17/07, via RT <bug-HTML-TreeBuilder-XPath@rt.cpan.org> wrote: Show quoted text
> > Sat Nov 17 03:30:36 2007: Request 30792 was acted upon. > Transaction: Ticket created by http://wassr.jp/user/tokuhirom > Queue: HTML-TreeBuilder-XPath > Subject: Cannot use id("Foo") > Broken in: (no value) > Severity: Important > Owner: Nobody > Requestors: tokuhirom@gmail.com > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=30792 > > > > If use XPath 'id("foo")' then follow error is occurred. > > Can't locate object method "getElementById" via package > "HTML::TreeBuilder::XPath" at > /usr/local/share/perl/5.8.8/XML/XPathEngine/Function.pm line 121. > > please add the method HTML::TreeBuilder::XPath->getElementById. > > follow is a patch for library and test. > > __END__ > > === lib/HTML/TreeBuilder/XPath.pm > ================================================================== > --- lib/HTML/TreeBuilder/XPath.pm (revision 7244) > +++ lib/HTML/TreeBuilder/XPath.pm (local) > @@ -11,6 +11,10 @@ > > use base( 'HTML::TreeBuilder'); > > +sub getElementById { > + my ($self, $id) = @_; > + ( $self->findnodes(qq{//*[\@id="$id"]}) )[0]; > +} > > package HTML::TreeBuilder::XPath::Node; > > === t/HTML-TreeBuilder-XPath.t > ================================================================== > --- t/HTML-TreeBuilder-XPath.t (revision 7244) > +++ t/HTML-TreeBuilder-XPath.t (local) > @@ -3,7 +3,7 @@ > > ######################### > > -use Test::More tests => 17; > +use Test::More tests => 18; > BEGIN { use_ok('HTML::TreeBuilder::XPath') }; > > ######################### > @@ -53,6 +53,8 @@ > > } > > +is( $html->findvalue('id("foo")/@id'), 'foo', 'id function'); > + > __END__ > /html/body/h1 1 Example header > //@id[.="toto"] 2 toto
Thanks, I am away for the weekend, so I'll apply the patch on Monday. I'll have to see if I can find a faster way to get the element than just going through the entire tree. -- mirod