1 9 10 package test.dom4j.xpath; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.Node; 16 import org.dom4j.XPath; 17 import test.dom4j.AbstractTestCase; 18 19 24 public class TestObject extends AbstractTestCase { 25 26 protected static boolean VERBOSE = true; 27 28 protected static String [] paths = { 29 "name(/.)", 30 "name()" 31 }; 32 33 34 public static void main( String [] args ) { 35 TestRunner.run( suite() ); 36 } 37 38 public static Test suite() { 39 return new TestSuite( TestObject.class ); 40 } 41 42 public TestObject(String name) { 43 super(name); 44 } 45 46 public void testXPaths() throws Exception { 49 Node element = document.selectSingleNode( "//author" ); 50 int size = paths.length; 51 for ( int i = 0; i < size; i++ ) { 52 testXPath( document, paths[i] ); 53 testXPath( element, paths[i] ); 54 } 55 } 56 57 protected void testXPath(Node node, String xpathText) { 60 XPath xpath = node.createXPath( xpathText ); 61 Object object = xpath.evaluate( node ); 62 63 log( "Searched path: " + xpath + " found: " + object ); 64 65 if ( VERBOSE ) { 66 log( " xpath: " + xpath ); 67 log( " for: " + node ); 68 } 69 } 70 } 71 72 73 74 75 119 | Popular Tags |