Reputation: 1085
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?
Upvotes: 3
Views: 467
Reputation: 243529
Read about the NamespaceManager and how to use it in EditX here: http://www.japisoft.com/doc-editix/manual/index.html#mozTocId544189
Upvotes: 0
Reputation: 56182
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']
Upvotes: 1