请教dom4j中文问题
在项目中需要用dom4j来读取一片xml,但是却发生了异常,那位高人能指教一二哦!?
xml:
<root><name>阿拉進髮</name></root>
java程序
String strXML = "<root><name>阿拉進髮</name></root>"; String strTemplateInfo = ""; StringBuffer objBuffer = new StringBuffer(strXML); org.dom4j.io.SAXReader objReader = null; InputStream objBufferInput = null; org.dom4j.Document objDom = null; org.dom4j.Element objElement = null; try { strTemplateInfo = objBuffer.toString(); objBufferInput = new StringBufferInputStream(strTemplateInfo); objReader = new org.dom4j.io.SAXReader(); objDom = objReader.read(objBufferInput); objElement = objDom.getRootElement(); System.out.print (objElement.asXML()); } catch (Exception ex) { System.out.print (ex.getMessage()); ex.printStackTrace(); }
Exception:
rror on line 1 of document : Invalid byte 2 of 2-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 2-byte UTF-8 sequence.org.dom4j.DocumentException: Error on line 1 of document : Invalid byte 2 of 2-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 2-byte UTF-8 sequence. at org.dom4j.io.SAXReader.read(SAXReader.java:339) at org.dom4j.io.SAXReader.read(SAXReader.java:246) at oracle.erp.test.DataGetter.getXMLRoot(DataGetter.java:132) at oracle.erp.test.DataGetter.testXml(DataGetter.java:42) at oracle.erp.test.DataGetter.main(DataGetter.java:37) Nested exception: org.xml.sax.SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:215) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:386) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1810) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242) at org.dom4j.io.SAXReader.read(SAXReader.java:323) at org.dom4j.io.SAXReader.read(SAXReader.java:246) at oracle.erp.test.DataGetter.getXMLRoot(DataGetter.java:132) at oracle.erp.test.DataGetter.testXml(DataGetter.java:42) at oracle.erp.test.DataGetter.main(DataGetter.java:37) Nested exception: org.xml.sax.SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:215) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:386) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1810) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242) at org.dom4j.io.SAXReader.read(SAXReader.java:323) at org.dom4j.io.SAXReader.read(SAXReader.java:246) at oracle.erp.test.DataGetter.getXMLRoot(DataGetter.java:132) at oracle.erp.test.DataGetter.testXml(DataGetter.java:42) at oracle.erp.test.DataGetter.main(DataGetter.java:37)
相关推荐
liaoxuewu 2020-04-10
ELEMENTS爱乐冬雨 2019-10-21
Yakamoz 2014-09-05
kenvie 2017-10-19
DodderB 2017-10-19
kenvie 2013-06-24
HiramYong 2013-04-14
Yakamoz 2014-09-05
realhero 2014-04-30
kenvie 2012-06-13
hongyuancao 2011-11-14
katelynlily 2012-09-07
Yakamoz 2012-06-20
道 2012-06-13
abchywabc 2012-04-16
kenvie 2012-03-06