You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Mark Biamonte <Ma...@merant.com> on 2001/04/05 18:43:02 UTC
RE: Bug/issue with default namespace & simple transform
I found this thread in the Xalan-Dev mailing list archives that addresses
the problem I am having. Unfortunately the last archive was from Dec 2000.
The last post in the thread (at least the last one that was archived)
included the following response from Scott Boag
============================================================================
====
> Otherwise, are we saying that there is no way to use XPath on documents
> which use namespaces but don't use prefixes?
You absolutely can. Put it this way: The *search* mechanism within the
XPath module never sees the prefixes... it doesn't care if "
http://com.company.aaa" was declared with xmlns:foo, xmlns:baz, or xmlns.
What it needs are namespace URIs on the source tree, and namespace URIs in
the XPath expression, which are resolved during the parse of the XPath.
The prefixes in the XPath expression are simply a notation to get you to
the namespace URIs. So, if in your source document you declare xmlns="
http://com.company.aaa", in the xpath expression you have to be more
specific: "aaa:doc/aaa:foo", and make sure that "aaa:" maps to "
http://com.company.aaa". You can do this either by creating a DOM where
"aaa:" has a xmlns:aaa="http://com.company.aaa" attribute (namespace decl)
on it, and hand it in as the namespaceNode parameter. OR, you can write a
class that implements PrefixResolver, and resolve the "aaa" prefix to "
http://com.company.aaa", and pass that to the eval method.
Sorry this is so confusing.
-scott
============================================================================
=========
This should work fine if you are creating the XPath expressions by hand.
However, I have an application that is creating XPath expressions
dynamically from an XML document and later evaluates them using the
XPathAPI. In order to have the above solution work I need to add code to
generate a prefix for any nodes that belong to the default namespace. While
this is quite do-able, it was not trivial and affects the perfomance of the
application. I found it much easier to modify my local copy of the XPath
expression parser to call the prefix resolver for all nodes, including nodes
with no namespace prefix. I can do this for this application becuase it is
only used internally. I wouldn't want to be deploying a customized version
of Xalan. This brings me to my question:
Why not make the XPath parser call the prefix resolver for all nodes
including nodes with out a namespace prefix and modify the default prefix
resolver to always return null for the namespace if there is no prefix (the
current default prefix resolver actually does resolve the default namespace
if one is defined)?
It seems like this would allow the XPath parser to adhere to the spec in the
default case but would allow a custom prefix resolver be specified if the
default namespace case needs to be handled with the XPathAPI.
Sorry if this issue has been previously resolved. I only have the archive
to go on.
Thanks
Mark