1 7 8 package org.dom4j.xpath; 9 10 import junit.textui.TestRunner; 11 12 import java.util.Iterator ; 13 import java.util.List ; 14 15 import org.dom4j.AbstractTestCase; 16 import org.dom4j.DocumentHelper; 17 import org.dom4j.Node; 18 import org.dom4j.XPath; 19 20 26 public class BooleanTest extends AbstractTestCase { 27 protected static String [] paths = {".[name()='author']", 28 ".[.='James Strachan']", ".[name()='XXXX']", ".[.='XXXX']", 29 "name()='author'", "name()='XXXX'", ".='James Strachan'", 30 ".='XXXX'"}; 31 32 public static void main(String [] args) { 33 TestRunner.run(BooleanTest.class); 34 } 35 36 public void testXPaths() throws Exception { 39 int size = paths.length; 40 41 for (int i = 0; i < size; i++) { 42 testXPath(paths[i]); 43 } 44 } 45 46 protected void testXPath(String xpathExpression) { 49 XPath xpath = DocumentHelper.createXPath(xpathExpression); 50 assertTrue("No xpath object was created", xpath != null); 51 52 log("Evaluating xpath: " + xpath); 53 54 List list = document.selectNodes("//author"); 55 56 for (Iterator iter = list.iterator(); iter.hasNext();) { 57 Node node = (Node) iter.next(); 58 testXPath(node, xpath); 59 } 60 } 61 62 protected void testXPath(Node node, XPath xpath) { 63 List list = xpath.selectNodes(node); 64 } 65 } 66 67 103 | Popular Tags |