jdom解析不了XML文件
本帖最后由 lihuai618 于 2010-11-02 15:46:44 编辑 xml文件如下:
<?xml version="1.0"?><music version="1.0"><command_name>order</command_name><command_data_block><code>2</code></command_data_block></music>
程序段代码:
StringBuffer inBuffer = new StringBuffer();
byte[] buffer = new byte[1];
while (in.read(buffer) != -1) {
inBuffer.append(new String(buffer));
}
SAXBuilder sax = new SAXBuilder(false);
Document doc = (Document) sax.build(new StringReader(inBuffer.toString().trim()));
错误:
org.jdom.input.JDOMParseException: Error on line 1: Document is invalid: no grammar found.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:946)
请问大虾如何解决?
[解决办法]
sax.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
sax.setFeature("http://xml.org/sax/features/validation", false);
使JDOM不去验证DTD