Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XPath on a node with namespace prefix

843834Oct 1 2009 — edited Nov 18 2009
Hello 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2009
Added on Oct 1 2009
3 comments
516 views