请xml解析的高手帮忙。
解析较长的一段xml后报异常,如果把字符串变短则能解析,请高手帮忙啊!
解析代码:
DataInputStream in = new DataInputStream(new ByteArrayInputStream(xmlstr.getBytes()));
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
xmlStream = builder.parse(in);
[Fatal Error] :69:1: 在文档的元素内容中找到无效 XML 字符 (Unicode: 0x0)。
org.xml.sax.SAXParseException: 在文档的元素内容中找到无效 XML 字符 (Unicode: 0x0)。
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
[解决办法]
应该不是长短问题,字符串里存在无效字符。 遍历一下ByteArray,有没有编码是0的空字符?