1 9 10 package test.dom4j; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.*; 16 import org.dom4j.io.SAXReader; 17 import org.ozoneDB.xml.dom4j.O3DocumentHelper; 18 19 import java.util.List ; 20 21 26 public class TestXPathBug extends AbstractTestCase { 27 28 public static void main( String [] args ) { 29 TestRunner.run( suite() ); 30 } 31 32 public static Test suite() { 33 return new TestSuite( TestXPathBug.class ); 34 } 35 36 public TestXPathBug(String name) { 37 super(name); 38 } 39 40 public void testXPaths() throws Exception { 43 SAXReader reader = new SAXReader(); 44 Document document = reader.read( "xml/rabo1ae.xml" ); 45 Element root = (Element) document.selectSingleNode( "/m:Msg/m:Contents/m:Content" ); 46 47 assertTrue( "root is not null", root != null ); 48 49 Namespace ns = root.getNamespaceForPrefix( "ab" ); 50 51 assertTrue( "Found namespace", ns != null ); 52 53 System.out.println( "Found: " + ns.getURI() ); 54 63 } 64 65 67 public void testRobLebowitz() throws Exception { 68 String text = "<ul>" 69 + " <ul>" 70 + " <li/>" 71 + " <ul>" 72 + " <li/>" 73 + " </ul>" 74 + " <li/>" 75 + " </ul>" 76 + "</ul>"; 77 78 Document document = O3DocumentHelper.parseText( text ); 79 List lists = document.selectNodes( "//ul | //ol" ); 80 81 int count = 0; 82 for (int i = 0; i < lists.size(); i++) { 83 Element list = (Element)lists.get(i); 84 List nodes = list.selectNodes("ancestor::ul"); 85 if ((nodes != null) && (nodes.size() > 0)) { 86 continue; 87 } 88 nodes = list.selectNodes("ancestor::ol"); 89 if ((nodes != null) && (nodes.size() > 0)) { 90 continue; 91 } 92 } 93 } 94 95 98 public void testStefan() throws Exception { 99 String text = "<foo>hello</foo>"; 100 Document document = O3DocumentHelper.parseText( text ); 101 XPath xpath = O3DocumentHelper.createXPath( "/x" ); 102 Object value = xpath.evaluate( document ); 103 } 104 105 106 108 public void testMikeSkells() throws Exception { 109 Document top = nodeFactory.createDocument(); 110 Element root = top.addElement("root"); 111 root.addElement("child1").addElement("child11"); 112 root.addElement("child2").addElement("child21"); 113 System.out.println(top.asXML()); 114 XPath test1 = top.createXPath("/root/child1/child11"); 115 XPath test2 = top.createXPath("/root/child2/child21"); 116 Node position1 = test1.selectSingleNode(root); 117 Node position2 = test2.selectSingleNode(root); 118 119 System.out.println("test1= "+test1); 120 System.out.println("test2= "+test2); 121 System.out.println("Position1 Xpath = "+position1.getUniquePath()); 122 System.out.println("Position2 Xpath = "+position2.getUniquePath()); 123 124 System.out.println("test2.matches(position1) : "+test2.matches(position1)); 125 126 assertTrue( "test1.matches(position1)", test1.matches(position1) ); 127 assertTrue( "test2.matches(position2)", test2.matches(position2) ); 128 129 assertTrue( "test2.matches(position1) should be false", ! test2.matches(position1) ); 130 } 131 132 } 133 134 135 136 137 181 | Popular Tags |