1 61 62 63 64 package org.jaxen.expr; 65 66 import java.util.List ; 67 68 import javax.xml.parsers.DocumentBuilderFactory ; 69 import javax.xml.parsers.ParserConfigurationException ; 70 71 import org.jaxen.JaxenException; 72 import org.jaxen.dom.DOMXPath; 73 import org.w3c.dom.Document ; 74 import org.w3c.dom.Element ; 75 76 import junit.framework.TestCase; 77 78 87 public class DefaultXPathExprTest extends TestCase 88 { 89 90 public void testJAXEN40() throws JaxenException, ParserConfigurationException { 91 92 DOMXPath xpath = new DOMXPath("root/child1/grandchild1 | root/child2/grandchild2"); 93 94 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 95 factory.setNamespaceAware(true); 96 Document doc = factory.newDocumentBuilder().newDocument(); 97 Element root = doc.createElement("root"); 98 Element child1 = doc.createElement("child1"); 99 Element child2 = doc.createElement("child2"); 100 Element grandchild1 = doc.createElement("grandchild1"); 101 Element grandchild2 = doc.createElement("grandchild2"); 102 root.appendChild(child1); 103 root.appendChild(child2); 104 child1.appendChild(grandchild1); 105 child2.appendChild(grandchild2); 106 107 doc.appendChild(root); 108 109 List results = xpath.selectNodes(doc); 110 assertEquals(2, results.size()); 111 assertTrue(results.indexOf(grandchild1) >= 0); 112 assertTrue(results.indexOf(grandchild2) >= 0); 113 114 } 115 116 } 117 | Popular Tags |