This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Query XML from Java 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 "Query XML from Java" Watch "Query XML from Java" New topic

Query XML from Java

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133

I am using the javax.xml.xpath to query an XML document. This prgram is working well with many XML. But in One XML where there is namespaces whenever I try to query it using //nodename it does not work. it only works with //* and it returns all the document. Any idea why is that??

Best Regards,

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

If "namespaces" refers to the default namespace then your problem is that XPath 1.0 does not find elements in the default namespace when you ask for them in the normal way by their name. You have to use workarounds likeOtherwise, I believe you have to call the setNamespaceContext() method before using the XPath object to define the namespace URI for each prefix.
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
Hi Paul,

Thanks a lot it worked..
but I do not get what was wrong with the first method.. Can you explain it again please :roll:


Don't get me started about those stupid light bulbs.
subject: Query XML from Java
Similar Threads
Database access using Java Script
XML b/w Servlets?
making XML Doc from JDBC Results
XML Parsing
making XML Doc from JDBC Results