commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lansing, Jeff" <jlans...@systechnologies.com>
Subject RE: [JXPATH] No value for xpath with default namespace prefix
Date Mon, 28 Feb 2005 21:33:07 GMT
Dimitri:
 
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"?>
<element-a>
  <element-b/>
</element-a>
 
vs. this:
 
<?xml version="1.0" encoding="UTF-8"?>
<element-a xmlns="urn:something">
  <element-b/>
</element-a>
 
which is identical in meaning to this:
 
<?xml version="1.0" encoding="UTF-8"?>
<foo:element-a xmlns:foo="urn:something">
  <foo:element-b/>
</foo:element-a>
 
And something like this makes no sense at all:
 
<element-a>
  <element-b xmlns="foo">
  </element-b>
</element-a>
 
the convention being that if you're in the "no namespace" namespace, then the whole document
has to be there.
 
Jeff

________________________________

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



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