1 7 8 package org.dom4j; 9 10 import junit.textui.TestRunner; 11 12 18 public class ParseTextTest extends AbstractTestCase { 19 protected String xmlText = 20 "<root><author name='James'><location>Paris</location></author></root>"; 21 22 public static void main(String [] args) { 23 TestRunner.run(ParseTextTest.class); 24 } 25 26 public void testDocument() throws Exception { 29 assertTrue("Document is not null", document != null); 30 31 Element root = document.getRootElement(); 32 33 assertTrue("Root element is not null", root != null); 34 35 Element author = root.element("author"); 36 37 assertTrue("Author element is not null", author != null); 38 39 String name = author.attributeValue("name"); 40 41 assertEquals("Name attribute matches", name, "James"); 42 43 String location = document.valueOf("/root/author/location"); 44 45 assertEquals("Location element matches", location, "Paris"); 46 } 47 48 protected void setUp() throws Exception { 51 super.setUp(); 52 document = DocumentHelper.parseText(xmlText); 53 } 54 } 55 56 92 | Popular Tags |