1 7 8 package org.dom4j.xpath; 9 10 import junit.textui.TestRunner; 11 12 import org.dom4j.AbstractTestCase; 13 import org.dom4j.Document; 14 import org.dom4j.Element; 15 import org.dom4j.Node; 16 17 23 public class SelectSingleNodeTest extends AbstractTestCase { 24 public static void main(String [] args) { 25 TestRunner.run(SelectSingleNodeTest.class); 26 } 27 28 public void testSelectSingleNode() throws Exception { 31 Document document = getDocument("/xml/test/jimBrain.xml"); 32 Node node = document.selectSingleNode("/properties/client/threadsafe"); 33 assertTrue("Found a valid node", node != null); 34 35 Element server = (Element) document 36 .selectSingleNode("/properties/server"); 37 assertTrue("Found a valid server", server != null); 38 39 Element root = document.getRootElement(); 40 server = (Element) root.selectSingleNode("/properties/server"); 41 assertTrue("Found a valid server", server != null); 42 43 server = (Element) document.selectSingleNode("properties/server"); 45 assertTrue("Found a valid server", server != null); 46 47 Element connection = (Element) server.selectSingleNode("db/connection"); 49 assertTrue("Found a valid connection", connection != null); 50 } 51 52 58 public void testSteensBug() throws Exception { 59 Document document = getDocument("/xml/schema/personal.xsd"); 60 61 String xpath = "/xs:schema/xs:element[@name='person']"; 62 assertNotNull("element is null", document.selectSingleNode(xpath)); 63 64 Element root = document.getRootElement(); 65 66 assertNotNull("element is null", root.selectSingleNode(xpath)); 67 } 68 } 69 70 106 | Popular Tags |