jaxen

JDOM navigator does selects with null namespace

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1
  • Fix Version/s: 1.1
  • Component/s: jdom
  • Labels:
    None
  • Number of attachments :
    0

Description

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(); }
}

}

Activity

Hide
Dominik Krupp added a comment -

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);
----------------------------------------------------

Show
Dominik Krupp added a comment - 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); ----------------------------------------------------
Hide
Elliotte Rusty Harold added a comment -

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.

Show
Elliotte Rusty Harold added a comment - 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.
Hide
Elliotte Rusty Harold added a comment -

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.

Show
Elliotte Rusty Harold added a comment - 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: