转载:http://hi.baidu.com/%C0%EE%D1%B8%D3%EE/blog/item/d9f0a9f043353206b07ec594.html
经考虑决定使用dom4j读取 xml 文件时因:dom4j读取文件时都先做 dtd 验证,占据大量时间,并且不连接网不能用,所以
解决方法:
public static Document load(File file){
Document document = null;
try {
SAXReader saxReader = new SAXReader();
saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxReader.setEncoding("UTF-8");
document = saxReader.read(file);
} catch (Exception ex) {
ex.printStackTrace();
}
return document;
}
在读文件时把 dtd 验证去掉 ,不仅使消除异常,而且功能运行时间从十几分钟缩短至 几秒.