Issue
While using xpath,
do we need to have a document name space aware to be able to use local-name
"//*[local-name()='Example']"
Form the tests I performed looks like it does not play a role, but this raises another question.
Does xpath care if the document is namespace aware or not ? Any pointer to rights docs or resources is appreciated. Thanks
Solution
No, you do not have to know a document name space when using local-name
.
The only difference between local-name
and name
is that local-name
will give you local name only, without the namespace (if exists) while name
will give you the name including the the namespace (if exists). See this explanation for more details.
In general, however, be aware that using local-host()
to defeat namespaces is not recommended. The purpose of XML namespaces is to allow names such as Example
to exist in an XML document from multiple XML vocabularies without conflict. Namespaces enable this capability and shouldn't be defeated without good reason. For examples of how to declare and use namespace prefixes for XPath in many different hosting languages and libraries, see How does XPath deal with XML namespaces?
Answered By - Prophet
Answer Checked By - Senaida (JavaFixing Volunteer)