1 7 8 package org.dom4j.io; 9 10 import junit.textui.TestRunner; 11 12 import java.io.StringWriter ; 13 14 import org.dom4j.AbstractTestCase; 15 16 import org.w3c.dom.NamedNodeMap ; 17 18 23 public class DOMWriterTest extends AbstractTestCase { 24 public static void main(String [] args) { 25 TestRunner.run(DOMWriterTest.class); 26 } 27 28 public void testNamespaceBug() throws Exception { 29 org.dom4j.Document doc = getDocument("/xml/namespaces.xml"); 30 DOMWriter writer = new DOMWriter(org.dom4j.dom.DOMDocument.class); 31 org.w3c.dom.Document result = writer.write(doc); 32 33 NamedNodeMap atts = result.getDocumentElement().getAttributes(); 34 assertEquals(4, atts.getLength()); 35 36 XMLWriter wr = new XMLWriter(); 37 wr.setOutputStream(System.out); 38 wr.write((org.dom4j.Document) result); 39 } 40 41 public void testBug905745() throws Exception { 42 org.dom4j.Document doc = getDocument("/xml/namespaces.xml"); 43 DOMWriter writer = new DOMWriter(); 44 org.w3c.dom.Document result = writer.write(doc); 45 46 NamedNodeMap atts = result.getDocumentElement().getAttributes(); 47 org.w3c.dom.Node versionAttr = atts.getNamedItem("version"); 48 assertNotNull(versionAttr); 49 assertNotNull(versionAttr.getLocalName()); 50 assertEquals("version", versionAttr.getLocalName()); 51 assertEquals("version", versionAttr.getNodeName()); 52 } 53 54 public void testBug926752() throws Exception { 55 org.dom4j.Document doc = getDocument("/xml/test/defaultNamespace.xml"); 56 DOMWriter writer = new DOMWriter(org.dom4j.dom.DOMDocument.class); 57 org.w3c.dom.Document result = writer.write(doc); 58 59 NamedNodeMap atts = result.getDocumentElement().getAttributes(); 60 assertEquals(1, atts.getLength()); 61 62 OutputFormat format = OutputFormat.createCompactFormat(); 63 format.setSuppressDeclaration(true); 64 65 XMLWriter wr = new XMLWriter(format); 66 StringWriter strWriter = new StringWriter (); 67 wr.setWriter(strWriter); 68 wr.write((org.dom4j.Document) result); 69 assertEquals("<a xmlns=\"dummyNamespace\"><b><c>Hello</c></b></a>", 70 strWriter.toString()); 71 } 72 } 73 74 110 | Popular Tags |