You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Tahura Chaudhry <ta...@hotmail.com> on 2004/10/20 20:01:34 UTC
XPath and Namespace mapping
I am new to Xalan. I have tried out the sample application "SimpleXPathAPI"
with the command as "SimpleXPathAPI foo.xml /doc name/@last" as instructed
in the docs. That resulted in the message: Warning -- No nodes matched the
location path "/doc".
When I gave the namespace prefix to the above command, i.e. "SimpleXPathAPI
foo.xml /foo:doc foo:name/@last" it correctly displayed the output "The
string value of the result is: Marston"
My question is if I didn'tt know ahead of time the prefix but know the
namespace, then is there a way to construct the XPath expression. Is there a
class which I can use to map arbitrary prefixes to namespaces and then uses
those prefixes as path of the XPath expression. If yes, what class is this?
thanks,
Tahura
Re: XPath and Namespace mapping
Posted by da...@us.ibm.com.
> My question is if I didn'tt know ahead of time the
> prefix but know the namespace, then is there a way
> to construct the XPath expression. Is there a class
> which I can use to map arbitrary prefixes to namespaces
> and then uses those prefixes as path of the XPath expression.
> If yes, what class is this?
The prefix is irrelevant -- you can use any prefix in an XPath expression,
as long as it is bound to the namespace URI of the target node(s) in the
XML document. All you need is to derive a class from PrefixResolver that
knows the prefix and namespace URI mappings for the XPath expressions, and
use that when you compile the XPath expression you are evaluating.
Dave