XPath on a node with namespace prefix
843834Oct 1 2009 — edited Nov 18 2009Hello everybody,
I have access to a org.w3c.dom.Node instance, on which I want to execute an XPath expression. The Node has namespace prefix, but not the namespace declaration. This is because the Node instance is obtained as the result of execution another XPath expression. The Node looks like the following.
<tns:Employee tns:id="E2">
<tns:Name>Roy Jaeson</tns:Name>
<tns:Gender>M</tns:Gender>
<tns:DateOfBirth>19831013</tns:DateOfBirth>
<tns:Designation>ASE</tns:Designation>
</tns:Employee>
I have tried setting NamespaceContext (containing the namespace to prefix mapping) on the XPath instance, but it doesn't seem to work. I have tried the following XPaths, none of which work.
1. /tns:Employee/tns:Name
2. /Employee/Name
3. /*[local-name()='Employee']/*[local-name()='Name']
What am I missing?
Edited by: kalyansarkar108 on Oct 1, 2009 3:36 AM