commons-user mailing list archives

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

The XPath specification does not allow an empty prefix: 
http://www.w3.org/TR/REC-xml-names/#NT-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-a>
  <element-b xmlns="foo">
  </element-b>
</element-a>

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" <jlansing@systechnologies.com>
To: <commons-user@jakarta.apache.org>
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 
correctly.

>>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 commons-user@jakarta.apache.org/2005-02/msg00117.html. 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.

Thanks,

Jeff

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message