Hi I have a doubt related to XPath.
My xml file looks as follows.
<?xml version="1.0" encoding="UTF-8"?>
<name xmlns="http://localhost/book" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://localhost/book books.xsd">
Java and XML
</name>
here is the xpath query and its result
/* - returns element "name"
/*/text() - returns text "Java and XML"
/name - no result
/name/text() - no result
Why specifying name is not giving any result?
That is because element name is declared in http://localhost/book. Therefore in XPath query you should specify it. As a rule you should pass to your XML engine namespace and it prefix, then query your XML using full-qualified name, i.e.:
/ns:name/text()
However you can use other technique specifying namespace in query, i.e.:
/*[local-name() = 'name' and namespace-uri() = 'http://localhost/book']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With