commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 32360] - [jxpath] Default Namespace not handled correctly
Date Sat, 22 Oct 2005 08:18:33 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=32360>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=32360





------- Additional Comments From agallardo@agsoftware.dnsalias.com  2005-10-22 10:18 -------
(In reply to comment #3)
> Richard,
> 
> Here's a question for you: Let's say I have a file that looks like this:
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <parent>
>   <test xmlns="http://test">
>     <child-element />
>   </test>
> </parent>
> 
> How do I access the child-element in this situation.
> 
> If I declare
>   context.registerNamespace(null, "http://test")

No, this should never be allowed. Because by definition, it should be always be:

context.registerNamespace(null, null)

> 
> and then try:
>   context.getValue("/parent/test/child-element")
> 
> I get nothing, because "parent" does not have "http://test" as its namespace.

Nope. I must return <child-element/>. I will try to explain why:


1-In http://www.w3.org/TR/xpath.html#dt-expanded-name states:

"The namespace URI is either null or a string."

2- In http://www.w3.org/TR/xpath.html#location-paths at the end we found that
the location path definition is recursive.

3- In http://www.w3.org/TR/xpath.html#node-tests we read:

"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:"

(I think the ending semi colon is important.)

Then in the next sentence of the same paragraph, they make clear that the
default namespace must be expanded to null:

"if the QName does not have a prefix, then the namespace URI is null."

By recursion (see 2), we conclude the default namespace of the first expression
context must be null too. Because the expression context of the root element,
does not have defined a default namespace too. Also, when we are in the root
element we already have the rule we cannot take into account the default
namespace, hence the default namespace becomes null all the time.

I think the specication is clear, in short:


Never take into account default namespaces, because they are always null by
definition. That also means they are equals all the time, then:

<parent> --> default namespace --> null
<test xmlns="http://test"> --> default namespace --> null.
<child-element />          --> default namespace --> null.

In that way,

context.getValue("/parent/test/child-element")

must return a <child-element/>


It does not matter is the doc is also defined:

<?xml version="1.0" encoding="iso-8859-1"?>
<parent xmlns="http://test">
  <test>
    <child-element/>
  </test>
</parent>

context.getValue("/parent/test/child-element");

here also context.getValue("/parent/test/child-element") should return
<child-element/>.


> In other words, as soon as I introduce a mapping for the empty prefix I seem to 
> lose the ability to access nodes that really don't have any namespace.  Does 
> this make sense?

Yes, for this reason, jxpath never must take into account the default namespaces.


> How should we resolve this conundrum?

:-)


Best Regards,

Antonio Gallardo.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


Mime
View raw message