Sample
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<ns2:bookStore xmlns:ns2="http://bookstore.com/schemes">
<ns2:book id="1">
<ns2:name>Data Structure</ns2:name>
</ns2:book>
<ns2:book id="2">
<ns2:name>Java Core</ns2:name>
</ns2:book>
</ns2:bookStore>
</Root>
Java code
XPathExpression expr =
xpath.compile("//Root/ns2:bookStore/ns2:book/ns2:name/text()");
I get Prefix must resolve to a namespace: ns2 error with above xml with Root
tag. By removing the Root tag I'm able to parse the data. Any help would be appreciated without modifying the XML file.