Details
-
Bug
-
Status: Resolved
-
Resolution: Duplicate
-
2.3
-
None
-
None
-
Operating System: Other
Platform: All
-
9801
Description
The following code simply sets the root element to the context node and
selects "ancestor-or-self()::node()". Expected result is a node-set
consisted of two nodes, Document and `root' Element, and actual result is
a node-set that has three nodes, Document, Document and `root' Element.
// ----------------------------------------------------------------
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.traversal.NodeIterator;
public class XPathBug0612 {
public static void main(String[] argv) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("root");
doc.appendChild(root);
NodeIterator nl = XPathAPI.selectNodeIterator(root, "ancestor-or-
self::node()");
Node n;
int i = 0;
while ((n = nl.nextNode()) != null)
// assertEquals(2, i);
}
}
// ----------------------------------------------------------------