Skip Menu |

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

Report information
The Basics
Id: 123663
Status: rejected
Priority: 0/
Queue: XML-LibXML

People
Owner: Nobody in particular
Requestors: tom.moreau [...] live.ca
Cc:
AdminCc:

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



Subject: contains() Works Only for First Element
Date: Sat, 18 Nov 2017 15:45:44 +0000
To: "bug-xml-libxml [...] rt.cpan.org" <bug-xml-libxml [...] rt.cpan.org>
From: Tom Moreau <tom.moreau [...] live.ca>
Given the following XML doc: <?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="children"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <author>James McGovern</author> <year>2003</year> <price>39.95</price> </book> <book category="web"> <title lang="en">XQuery Kick Start</title> <author>Per Bothner</author> <author>James McGovern</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> </bookstore> If I use the contains() function for books that have an author whose name contains the string McGovern, it works only if McGovern is the first author. Test script below: use strict 'vars'; use IO::Handle; use XML::Simple; use XML::LibXML qw( ); use Data::Dumper; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file('Books.xml'); my @Titles = map {$_->to_literal} $doc->findnodes(q {//book[contains(author, "McGovern")]/title}); # my @Titles = map {$_->to_literal} $doc->findnodes(q {//book[author = "James McGovern"]/title}); print Dumper (@Titles); If I specify an exact match on the full author name, it finds the books. Tom Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS Cambridge, ON Canada tom.moreau@live.ca<mailto:tom.moreau@live.ca>
On 2017-11-18 10:45:57, tom.moreau@live.ca wrote: Show quoted text
> Given the following XML doc: > > <?xml version="1.0" encoding="UTF-8"?> > > <bookstore> > > <book category="cooking"> > <title lang="en">Everyday Italian</title> > <author>Giada De Laurentiis</author> > <year>2005</year> > <price>30.00</price> > </book> > > <book category="children"> > <title lang="en">Harry Potter</title> > <author>J K. Rowling</author> > <year>2005</year> > <price>29.99</price> > </book> > > <book category="web"> > <title lang="en">Learning XML</title> > <author>Erik T. Ray</author> > <author>James McGovern</author> > <year>2003</year> > <price>39.95</price> > </book> > > <book category="web"> > <title lang="en">XQuery Kick Start</title> > <author>Per Bothner</author> > <author>James McGovern</author> > <author>Kurt Cagle</author> > <author>James Linn</author> > <author>Vaidyanathan Nagarajan</author> > <year>2003</year> > <price>49.99</price> > </book> > > </bookstore> > > If I use the contains() function for books that have an author whose > name contains the string McGovern, it works only if McGovern is the > first author. Test script below: > > use strict 'vars'; > use IO::Handle; > use XML::Simple; > use XML::LibXML qw( ); > use Data::Dumper; > > my $parser = XML::LibXML->new(); > my $doc = $parser->parse_file('Books.xml'); > > my @Titles = map {$_->to_literal} $doc->findnodes(q > {//book[contains(author, "McGovern")]/title}); > # my @Titles = map {$_->to_literal} $doc->findnodes(q > {//book[author = "James McGovern"]/title}); > print Dumper (@Titles); > > If I specify an exact match on the full author name, it finds the > books. >
Probably reading https://stackoverflow.com/questions/1064968/how-to-use-xpath-contains-here helps here. Changing the XPath to //book[./author[contains(.,'McGovern')]]/title seems to return what you want. Regards, Slaven
Subject: RE: [rt.cpan.org #123663] contains() Works Only for First Element
Date: Sat, 18 Nov 2017 16:23:27 +0000
To: "bug-XML-LibXML [...] rt.cpan.org" <bug-XML-LibXML [...] rt.cpan.org>
From: Tom Moreau <tom.moreau [...] live.ca>
That worked! Thanx. :)      Tom     Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS Cambridge, ON Canada    tom.moreau@live.ca Show quoted text
-----Original Message----- From: Slaven_Rezic via RT [mailto:bug-XML-LibXML@rt.cpan.org] Sent: November 18, 2017 11:04 To: tom.moreau@live.ca Subject: [rt.cpan.org #123663] contains() Works Only for First Element <URL: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Frt.cpan.org%2FTicket%2FDisplay.html%3Fid%3D123663&data=02%7C01%7Ctom.moreau%40live.ca%7C30a32f98a3a34e55d9ba08d52e9e058b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636466178582623689&sdata=psKc15cicVDRpxNQYa66emaumkEygvH264GoAiMXj7c%3D&reserved=0 > On 2017-11-18 10:45:57, tom.moreau@live.ca wrote:
> Given the following XML doc: > > <?xml version="1.0" encoding="UTF-8"?> > > <bookstore> > > <book category="cooking"> > <title lang="en">Everyday Italian</title> <author>Giada De > Laurentiis</author> > <year>2005</year> > <price>30.00</price> > </book> > > <book category="children"> > <title lang="en">Harry Potter</title> > <author>J K. Rowling</author> > <year>2005</year> > <price>29.99</price> > </book> > > <book category="web"> > <title lang="en">Learning XML</title> > <author>Erik T. Ray</author> > <author>James McGovern</author> > <year>2003</year> > <price>39.95</price> > </book> > > <book category="web"> > <title lang="en">XQuery Kick Start</title> > <author>Per Bothner</author> > <author>James McGovern</author> > <author>Kurt Cagle</author> > <author>James Linn</author> > <author>Vaidyanathan Nagarajan</author> > <year>2003</year> > <price>49.99</price> > </book> > > </bookstore> > > If I use the contains() function for books that have an author whose > name contains the string McGovern, it works only if McGovern is the > first author. Test script below: > > use strict 'vars'; > use IO::Handle; > use XML::Simple; > use XML::LibXML qw( ); > use Data::Dumper; > > my $parser = XML::LibXML->new(); > my $doc = $parser->parse_file('Books.xml'); > > my @Titles = map {$_->to_literal} $doc->findnodes(q > {//book[contains(author, "McGovern")]/title}); > # my @Titles = map {$_->to_literal} $doc->findnodes(q > {//book[author = "James McGovern"]/title}); print Dumper (@Titles); > > If I specify an exact match on the full author name, it finds the > books. >
Probably reading https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1064968%2Fhow-to-use-xpath-contains-here&data=02%7C01%7Ctom.moreau%40live.ca%7C30a32f98a3a34e55d9ba08d52e9e058b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636466178582623689&sdata=EzbjqwrXJ1PDWMtVD64uP2deKnrP%2FITBev4UKe9iP4M%3D&reserved=0 helps here. Changing the XPath to //book[./author[contains(.,'McGovern')]]/title seems to return what you want. Regards, Slaven
On Sat Nov 18 11:23:44 2017, tom.moreau@live.ca wrote: Show quoted text
> That worked! Thanx. :) >
marking as INVALID then - glad it helped.