1 7 8 package org.dom4j; 9 10 import junit.textui.TestRunner; 11 12 import java.util.List ; 13 14 import org.dom4j.dtd.ElementDecl; 15 import org.dom4j.io.SAXReader; 16 17 23 public class DocTypeTest extends AbstractTestCase { 24 25 protected static final String INPUT_XML_FILE = "/xml/dtd/internal.xml"; 26 27 public static void main(String [] args) { 28 TestRunner.run(DocTypeTest.class); 29 } 30 31 public void testDocType() throws Exception { 34 SAXReader reader = new SAXReader(); 35 reader.setIncludeInternalDTDDeclarations(true); 36 37 Document document = getDocument(INPUT_XML_FILE, reader); 38 39 DocumentType docType = document.getDocType(); 40 assertTrue("Has DOCTYPE", docType != null); 41 42 List declarations = docType.getInternalDeclarations(); 43 assertTrue("DOCTYPE has declarations", (declarations != null) 44 && !declarations.isEmpty()); 45 46 ElementDecl decl = (ElementDecl) declarations.get(0); 47 48 assertEquals("name is correct", "greeting", decl.getName()); 49 assertEquals("model is correct", "(#PCDATA)", decl.getModel()); 50 51 String expected = "<!ELEMENT " + decl.getName() + " " + decl.getModel() 52 + ">"; 53 assertEquals("toString() is correct", expected, decl.toString()); 54 } 55 } 56 57 93 | Popular Tags |