首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

dom4j解析含有中文字符的xml报Invalid byte 1 of 1-byte UTF-8 sequence

2012-08-26 
dom4j解析带有中文字符的xml报Invalid byte 1 of 1-byte UTF-8 sequence.String result?xml version\

dom4j解析带有中文字符的xml报Invalid byte 1 of 1-byte UTF-8 sequence.
String result="<?xml version="1.0" encoding="UTF-8"?><root>测试</root>";
SAXReader sr = new SAXReader();
ByteArrayInputStream input = new ByteArrayInputStream(result
.getBytes());
Document doc = sr.read(input);
Element root = doc.getRootElement();
Iterator<Element> it = root.elementIterator();
while(it.hasNext()){
Element element=it.next();
}

报 Invalid byte 1 of 1-byte UTF-8 sequence. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence.错误

解决方法之一

<?xml version="1.0" encoding="UTF-8"?>中的UTF-8改写成GBK或者GB2312。
没有这个标签,可以添加这个标签。

热点排行