CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
XPath Help

 



akhilak
Novice

Oct 24, 2007, 10:16 PM

Post #1 of 1 (699 views)
XPath Help Can't Post

Hello All,
I have a sample XML file

<book>
--<bookstore>
----<bookstorename>Big books</bookstorename>
----<bookslist>
------<bookname>
----------<title lang="eng">Harry Potter</title>
----------<price>29.99</price>
------</bookname>
------<bookname>
----------<title lang="eng">Learning XML</title>
----------<price>39.95</price>
------</bookname>
------<ordernumber>2</ordernumber>
----</bookslist>
----<address>123 Street, NY</address>
--</bookstore>
--<bookstore>
----<bookstorename>Small books</bookstorename>
----<bookslist>
------<bookname>
----------<title lang="eng">Chronicles of Narnia</title>
----------<price>19.99</price>
------</bookname>
------<bookname>
----------<title lang="eng">Learning Perl</title>
----------<price>49.95</price>
------</bookname>
------<ordernumber>2</ordernumber>
----</bookslist>
----<address>321 Street, NJ</address>
--</bookstore>
</book>

I want to find the number of occurences of the bookname node inside the first occurence of bookslist.
I am using XPAth here.
I used the syntax as
$count = $xp->find('count(//bookslist[1]/bookname)');
It is returning the value as 4 instead of 2. But when trying with
$count = $xp->find('count(//book[1]/bookstore)');
or
$count = $xp->find('count(//bookstore[1]/bookslist)'); it is returning the value correctly. I dont understand this problem. I dont want to give the full path with the names of the ancestors like
$count = $xp->find('count(/book/bookstore/bookslist[1]/bookname)');

Please help!
Thanks in advance.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives