> C:\>XPathWrapper c:\xpathtest.xml / /rootns:root:/q1:foo 
> The sample works if the namespace declaration for q1 is moved to the 
root node.
> However, we cannot change the declaration.  The issue  occurs in the 
execute
> statement in the code. 

XPathWrapper is meant as a demonstration sample, not as production code. 
It has the limitation that any namespace bindings you use must be declared 
on the document element.

> theXPathProcessor.initXPath(*contextXPath, 
>             theXPathConstructionContext, 
>                         XalanDOMString(strQuery.c_str()), 
>                         ElementPrefixResolverProxy(rootElem, 
theEnvSupport, theDOMSupport)); 
> 
> XObjectPtr      xObj = contextXPath->execute(currentNode, 
>                         ElementPrefixResolverProxy(rootElem, 
theEnvSupport, theDOMSupport), 
>                         theExecutionContext); 

You do exactly what XPathWrapper does -- you create an 
ElementPrefixResolverProxy and give it the document element.  So, the only 
namespace bindings available are those declared on that element.

What you need is another implementation of the PrefixResolver abstract 
base class that knows about the prefixes and namespace URIs you are 
interested in.  You can implement your own, or you can use an instance of 
XalanDocumentPrefixResolver, if you want to make all of the namespace 
bindings in the entire document available.  Beware, however, that this is 
less efficient than creating your own PrefixResolver that only knows about 
the prefixes you are interested in.  Also, XalanDocumentPrefixResolver 
does not work well when a document contains multiple namespace 
declarations for the same prefix, but with different namespace URIs.

Dave

Reply via email to