1 7 8 package org.dom4j; 9 10 import junit.textui.TestRunner; 11 12 import java.util.List ; 13 14 import org.dom4j.util.IndexedDocumentFactory; 15 16 22 public class IndexedElementTest extends AbstractTestCase { 23 public static void main(String [] args) { 24 TestRunner.run(IndexedElementTest.class); 25 } 26 27 public void testXPaths() throws Exception { 30 testXPath("//author"); 31 } 32 33 protected void testXPath(String xpath) { 36 List list = document.selectNodes(xpath); 37 38 log("Searched path: " + xpath); 39 log("Found : " + list.size() + " result(s)"); 40 41 log("Results"); 42 43 if (list == null) { 44 log("null"); 45 } else { 46 log("["); 47 48 for (int i = 0, size = list.size(); i < size; i++) { 49 Object object = list.get(i); 50 String text = "null"; 51 52 if (object instanceof Node) { 53 Node node = (Node) object; 54 text = node.asXML(); 55 } else if (object != null) { 56 text = object.toString(); 57 } 58 59 log(" " + text); 60 } 61 62 log("]"); 63 } 64 65 log("..........................................."); 66 67 assertTrue("Found some results", list.size() > 0); 68 } 69 70 protected Document createDocument() { 71 return IndexedDocumentFactory.getInstance().createDocument(); 72 } 73 } 74 75 111 | Popular Tags |