关于dom4j的utf-8编码的问题
我组了一个XML字符串,解析过程如下,但是报错:
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.dom4j.Document;
import org.dom4j.Node;
import
org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
public class TestDom4j {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String sXml = " <?xml version=\ "1.0\ " encoding=\ "utf-8\ "?> <ROOT> <TABLE> 哈哈哈哈 </TABLE> </ROOT> ";
SAXReader saxReader = new SAXReader();
InputStream inputStream = new ByteArrayInputStream(sXml.getBytes());
try {
Document document = saxReader.read(inputStream);
} catch (DocumentException e) {
// TODO Auto-generated catch block