jQuery in Action, 2nd edition*
The moose likes Web Services and the fly likes XPath with namespace 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 » Java » Web Services
Bookmark "XPath with namespace" Watch "XPath with namespace" New topic
Author

XPath with namespace

Max Bogdanov
Greenhorn

Joined: Mar 12, 2011
Posts: 11

Hello!
I have no idea why this simple example does not work. Please give me same advice:
(if I remove namespace it works perfect)



Example output:



NamespaceContext implementation class:


Thanks, Max

OC-JA,OCP-JP,OCP-JWCD,OCE-EJBD,OCE-JPAD
N Sahni
Ranch Hand

Joined: Jul 07, 2011
Posts: 55

Hi,

Everything looks good here except the namespace.
The namespace declared in xml is whereas namaspace set in namaspacecontext is Both does not match.


Thanks and Regards,
Nilesh Sahni | nsahni@infocepts.com | www.infocepts.com
Max Bogdanov
Greenhorn

Joined: Mar 12, 2011
Posts: 11

N Sahni wrote:Hi,

Everything looks good here except the namespace.
The namespace declared in xml is whereas namaspace set in namaspacecontext is Both does not match.


It was my copy-paste mistake. I edited my post, the namespaces are same, I checked everything 1000 times))). Thanks.
N Sahni
Ranch Hand

Joined: Jul 07, 2011
Posts: 55

Can you try modifying DocumentBuilderFactory instance like this:

I tried executing your code and replicating the issue. By setting builder.setNamespaceAware(true); it worked properly.
Max Bogdanov
Greenhorn

Joined: Mar 12, 2011
Posts: 11

N Sahni wrote:Can you try modifying DocumentBuilderFactory instance like this:

I tried executing your code and replicating the issue. By setting builder.setNamespaceAware(true); it worked properly.


Thank you so much! Now it works. I didn't know that default value is false.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XPath with namespace
 
Similar Threads
Namespance prefix transparent XPath lookup
WSDL2Java Question
Java Web Services 2
selectNodeIterator() problem
Binding XML to Java from SOAP message