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 Moddy Te'eni <mt...@informatica.com> on 2009/06/17 08:36:45 UTC

empty prefix for a non-empty namespace in XPath

I'm trying to evaluate XPath expression on an input that looks like:

<Document xmlns="myNamespace/whatever">  ....

When I simply use "/Document", it doesn't work.

In order to overcome this problem, I wrote my own PrefixResolver, which
always returns "myNamespace/whatever", and then I can use the xpath 
"/aaa:Document", but I still can't use the simpler form. The PrefixResolver
is never called for an empty prefix.

This could be how it should work according to w3c. I'm not sure about it.

However, if it is not - how can I tell Xalan what is the namespace of the
empty prefix?

Thanks, Moddy.

-- 
View this message in context: http://www.nabble.com/empty-prefix-for-a-non-empty-namespace-in-XPath-tp24067797p24067797.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.


Re: empty prefix for a non-empty namespace in XPath

Posted by David Bertoni <db...@apache.org>.
Moddy Te'eni wrote:
> I'm trying to evaluate XPath expression on an input that looks like:
> 
> <Document xmlns="myNamespace/whatever">  ....
> 
> When I simply use "/Document", it doesn't work.
> 
> In order to overcome this problem, I wrote my own PrefixResolver, which
> always returns "myNamespace/whatever", and then I can use the xpath 
> "/aaa:Document", but I still can't use the simpler form. The PrefixResolver
> is never called for an empty prefix.
> 
> This could be how it should work according to w3c. I'm not sure about it.
Yes, this is explicit in the XPath recommendation:

http://www.w3.org/TR/xpath#node-tests

"A QName in the node test is expanded into an expanded-name using the 
namespace declarations from the expression context. This is the same way 
expansion is done for element type names in start and end-tags except 
that the default namespace declared with xmlns is not used: if the QName 
does not have a prefix, then the namespace URI is null (this is the same 
way attribute names are expanded). It is an error if the QName has a 
prefix for which there is no namespace declaration in the expression 
context."

> 
> However, if it is not - how can I tell Xalan what is the namespace of the
> empty prefix?
You can't.  QNames without prefixes are always interpreted as having a 
null namespace URI.

Dave