Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error while executing xpath expression on a NodeList

843834Dec 28 2005 — edited Jan 3 2006
Hi
the following is the code snippet where I am obtaining a NodeList and then passing the nodelist to another xpath evaluate function.

I am not able to execute the xpath expression on the node list. Can you please tell me what could be the error...

The code and XML file are as below...
String xpathExpr = "/library/country/books";
NodeList nlist =  (NodeList)xpathEvaluator.evaluate(xpathExpr, w3cdom, XPathConstants.NODESET);       
 xpathExpr = "/books/book/title";
String value  = (String)xpathEvaluator.evaluate(xpathExpr, nlist,  XPathConstants.STRING)
System.out.println("VALUE ==== " + value);
<?xml version="1.0" encoding="UTF-8"?>
<library>
<country>
<books>
<book type="hardback" lang="EN">
<title>Atlas & Shrugged</title>
<author>Ayn Rand</author>
<isbn>0525934189</isbn>
<price>39.95</price>
</book>
<book type="paperback" lang="JP">
<title>A Burnt-Out Case</title>
<author>Graham Greene</author>
<isbn>0140185399</isbn>
<price>13.00</price>
</book>
</books>
</country>
 
<country>
<books>
<book type="hardback" lang="EN">
<title>Atlas & Shrugged</title>
<author>Ayn Rand</author>
<isbn>0525934189</isbn>
<price>39.95</price>
</book>
<book type="paperback" lang="JP">
<title>A Burnt-Out Case</title>
<author>Graham Greene</author>
<isbn>0140185399</isbn>
<price>13.00</price>
</book>
</books>
</country>
</library>
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 31 2006
Added on Dec 28 2005
12 comments
1,204 views