History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JAXEN-158
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Elliotte Rusty Harold
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
jaxen

JDOM navigator does selects with null namespace

Created: 19/Sep/06 02:36 PM   Updated: 21/Sep/06 06:45 AM
Component/s: jdom
Affects Version/s: 1.1
Fix Version/s: 1.1

Time Tracking:
Not Specified


 Description  « Hide
From Dominik Krupp:

here is an even simpler but runnable example.
All three paths have the same Xpath namespace scopes. I still think
there should be zero selected nodes with the "/root" path, but there is one.

My output with JDOM 1.0 and Jaxen 1.1beta10 in classpath:

Element root has namespace URI: http://mynamespace.org/
Size of node set (/root): 1
Size of node set (/my:root): 1
Size of node set (/foreign:root): 0

Program producing that output:

import java.util.List;
import org.jaxen.JaxenException;
import org.jaxen.XPath;
import org.jaxen.jdom.JDOMXPath;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;

public class NullNamespaceXpath {

public static void main(String[] args) {
Namespace my = Namespace.getNamespace("my",
"http://mynamespace.org/");
Document doc = new Document();
Element root = new Element("root", my);
doc.setRootElement(root);
try { XPath nullNamespacePath = new JDOMXPath("/root"); nullNamespacePath.addNamespace("my", "http://mynamespace.org/"); nullNamespacePath.addNamespace("foreign", "http://foreignnamespace.org/"); XPath myNamespacePath = new JDOMXPath("/my:root"); myNamespacePath.addNamespace("my", "http://mynamespace.org/"); myNamespacePath.addNamespace("foreign", "http://foreignnamespace.org/"); XPath foreignNamespacePath = new JDOMXPath("/foreign:root"); foreignNamespacePath.addNamespace("my", "http://mynamespace.org/"); foreignNamespacePath.addNamespace("foreign", "http://foreignnamespace.org/"); List selectedNodesNullNamespace = nullNamespacePath .selectNodes(doc); List selectedNodesMyNamespace = myNamespacePath.selectNodes(doc); List selectedNodesForeignNamespace = foreignNamespacePath .selectNodes(doc); System.out.println("Element root has namespace URI: " + root.getNamespaceURI()); System.out.println("Size of node set (/root): " + selectedNodesNullNamespace.size()); System.out.println("Size of node set (/my:root): " + selectedNodesMyNamespace.size()); System.out.println("Size of node set (/foreign:root): " + selectedNodesForeignNamespace.size()); } catch (JaxenException e) { e.printStackTrace(); }
}

}



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Dominik Krupp - 21/Sep/06 03:38 AM
I'm not a jaxen committer but I think it could suffice to add the following lines in org.jaxen.jdom.DocumentNavigator#getChildAxisIterator(Object,String,String,String) to fix the problem, because it only occurs when the context node is a Document, not when it is an Element.

----------------------------------------------------
else if(el.getNamespace() != null) { return JaxenConstants.EMPTY_ITERATOR; }
----------------------------------------------------

Insert just before the following line
----------------------------------------------------
return new SingleObjectIterator(el);
----------------------------------------------------


Elliotte Rusty Harold - 21/Sep/06 05:29 AM
While that would fix this issue, it breaks 21 other unit tests. Still that gives me an idea where to look to fix this, and that's helpful.

P.S. Even if you aren't a committer you can still check out the code, and run the tests; then submit a patch if you figure out how to fix this. That's how people get to be committers.


Elliotte Rusty Harold - 21/Sep/06 06:45 AM
This should be fixed now. The fix you proposed was very close. However, in JDOM no namespace is indicated by the constant Namespace.NO_NAMESPACE, not by null. Once I changed <code>el.getNamespace() != null</code> to <code>el.getNamespace() != Namespace.NO_NAMESPACE</code> all tests passed.