Hi Dave,

If I have namespace like xmlns:ns = "http://....."; in my xmal file
(sample.xml) then I can use the xpath expression as you suggested
("//ns:message").

This xpath expression is able to retrieve desired results with the
following xpathevaluator with out using prefixresolver.

        evaluator.selectNodeList( nodelist,
                                                  dom_support,
                                       root_context_node,
                                                  expression.c_str(),
                                                  namespace_node);

But my question is how do we need to give xpath expression if we have
default namespace(xmlsns="http://....).

-----Original Message-----
From: David Bertoni [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 08, 2007 11:47 PM
To: xalan-c-users@xml.apache.org
Subject: Re: xpath expression with namespace

Nageswar, Jaya wrote:
> Whenever I have a default namespace in my xml file, xpath expression
is 
> not returning any nodeset.
> 
>  
>
..

> 
> I am trying to use xpath expression as "//message". My code is as 
> follows. I am using xerces as well as xalan in my application.
>
..
> Since I have default namespace xmlns=http://schemas.xmlsoap.org/wsdl/
in 
> my input xml file I'm getting length as zero.
> 
> If I remove the default namespace them I am getting length as 3 which
is 
> correct for my xpath expression.
> 
> Please help me how xpath expression needs to be modified whenever we 
> have default namespace.
> 
> Any help regarding xpath expressions whenever there are namespaces in 
> the xml file are appreciated.
You need to use a namespace prefix in your XPath expressions:

"//ns:message"

You'll also need to implement a PrefixResolver derivative and pass an 
instance of that into the XPathEvaluator, so the XPath implementation
can 
map the namespace prefix to the proper namespace URI.  You can look at
the 
existing PrefixResolver instances to see what's involved.

Dave

Reply via email to