1 7 8 package org.dom4j.io; 9 10 import junit.textui.TestRunner; 11 12 import java.io.ByteArrayOutputStream ; 13 import java.io.File ; 14 import java.io.StringWriter ; 15 16 import org.dom4j.AbstractTestCase; 17 import org.dom4j.Document; 18 import org.dom4j.Element; 19 20 26 public class XPP3ReaderTest extends AbstractTestCase { 27 public static void main(String [] args) { 28 TestRunner.run(XPP3ReaderTest.class); 29 } 30 31 public void testRussian() throws Exception { 34 File file = getFile("/xml/russArticle.xml"); 35 XPP3Reader xmlReader = new XPP3Reader(); 36 Document doc = xmlReader.read(file); 37 Element el = doc.getRootElement(); 38 39 StringWriter writer = new StringWriter (); 40 XMLWriter xmlWriter = new XMLWriter(writer); 41 OutputFormat format = OutputFormat.createPrettyPrint(); 42 format.setEncoding("koi8-r"); 43 xmlWriter.write(doc); 44 log(writer.toString()); 45 } 46 47 public void testRussian2() throws Exception { 48 File file = getFile("/xml/russArticle.xml"); 49 XPP3Reader xmlReader = new XPP3Reader(); 50 Document doc = xmlReader.read(file); 51 XMLWriter xmlWriter = new XMLWriter(new OutputFormat("", false, 52 "koi8-r")); 53 ByteArrayOutputStream out = new ByteArrayOutputStream (); 54 xmlWriter.setOutputStream(out); 55 xmlWriter.write(doc); 56 xmlWriter.flush(); 57 xmlWriter.close(); 58 log(out.toString()); 59 } 60 } 61 62 98 | Popular Tags |