commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lansing, Jeff" <>
Subject RE: [JXPATH] No value for xpath with default namespace prefix
Date Mon, 28 Feb 2005 21:33:07 GMT
I hadn't really noticed this fact before:
[6] 	 QName	 ::= 	(Prefix ':')? LocalPart	
[7] 	 Prefix	 ::= 	NCName	
[8] 	 LocalPart	 ::= 	NCName	
It seems to me that in practice people distinguish between the "no namespace" namespace, and
a namespace that currently has "" as its prefix.
In this way you get this ("no namespace" namespace):
<?xml version="1.0" encoding="UTF-8"?>
vs. this:
<?xml version="1.0" encoding="UTF-8"?>
<element-a xmlns="urn:something">
which is identical in meaning to this:
<?xml version="1.0" encoding="UTF-8"?>
<foo:element-a xmlns:foo="urn:something">
And something like this makes no sense at all:
  <element-b xmlns="foo">
the convention being that if you're in the "no namespace" namespace, then the whole document
has to be there.


From: Dmitri Plotnikov []
Sent: Mon 2/28/2005 11:37 AM
To: Jakarta Commons Users List
Subject: Re: [JXPATH] No value for xpath with default namespace prefix


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