commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Plotnikov" <>
Subject Re: [JXPATH] No value for xpath with default namespace prefix
Date Mon, 28 Feb 2005 19:37:59 GMT

The XPath specification does not allow an empty prefix:, and a missing prefix is 
always mapped to the null namespace.

The problem is not the implementation (I would change the implementation to 
accomodate whatever decision is made), but rather conceptual.  And the 
problem is this:  If we allow the null (or empty) prefix to be mapped in the 
context, we lose the ability to reference elements that don't have any 
namespace at all.  E.g.

  <element-b xmlns="foo">

If we map "pfx" to "foo" in the context, we can reference element-a like 
this: "element-a" and element-b like this: "element-a/pfx:element-b".

If, on the other hand, null is mapped to "foo", we cannot reference 
element-a, because the path "element-a" would be looking for element-a with 
the namespace foo.  We cannot reference element-b directly either: 
"element-a/element-b" would not find element-a.  The only way to reference 
element-b would be to bypass element-a: "//element-b", which is IMO an 
unacceptable limitation.

I am open to suggestions.

- Dmitri

----- Original Message ----- 
From: "Lansing, Jeff" <>
To: <>
Sent: Monday, February 28, 2005 12:48 PM
Subject: [JXPATH] No value for xpath with default namespace prefix

Commons-jxpath-1.2 does not seem to handle the default namespace prefix 

>>From the documentation:

XPath matches qualified names (QNames) based on the namespace URI, not on 
the prefix. Therefore the XPath "//foo:bar" may not find a node named 
"foo:bar" if the prefix "foo" in the context of the node and in the 
execution context of the XPath are mapped to different URIs. Conversely, 
"//foo:bar" will find the node named "biz:bar", if "foo" in the execution 
context and "biz" in the node context are mapped to the same URI.

The way to do this is evidently to register "foo", as in: 
JXPathContext.registerNamespace("foo", "biz's namespace URI").

But this does not work for the prefix "", as in 
JXPathContext.registerNamespace("", "biz's namespace URI").
JXPathContext.getValue("//bar") will throw  JXPathException: No value for 
xpath:  in this case.

A similar problem (or the same underlying problem) and a suggested fix was 
reported in I have 
tried applying this fix, but it doesn't solve this problem.

I too have looked at the source code for JXpath, and I suspect the real 
problem may be a deficiency in the parser grammar.



To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message