wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Xpath with name space? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Xpath with name space?" Watch "Xpath with name space?" New topic
Author

Xpath with name space?

John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
Hi,
I have the following xml:


I need to access to the "def1" node. The xpath abc/def1 is not right. What should I include in side the xpath for the namespace?

Thanks,
John.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

In plain XPath there isn't any way to refer to elements in the default namespace. But if you have a way of providing a namespace context to your XPath expression, then do this:

(1) Provide a namespace context that maps your namespace URI ("abc123" in this case) to a prefix, let's say "x" for example.

(2) Write your XPath expression as "x:abc/x:def1".
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Xpath with name space?
 
Similar Threads
Questions on Requirements for Assignment..
Problem with xPath
problem with code....
schema key/keyref
Populating JList in Parent window from Child window's save button