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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
XPath Help



Oct 24, 2007, 10:16 PM

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

Hello All,
I have a sample XML file

----<bookstorename>Big books</bookstorename>
----------<title lang="eng">Harry Potter</title>
----------<title lang="eng">Learning XML</title>
----<address>123 Street, NY</address>
----<bookstorename>Small books</bookstorename>
----------<title lang="eng">Chronicles of Narnia</title>
----------<title lang="eng">Learning Perl</title>
----<address>321 Street, NJ</address>

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)');
$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