标签:
2,xml文件
3,错误如下
三、分析原因
当执行build的时候jdom分析到
DOCTYPE workflow PUBLIC "-/OpenSymphony Group//DTD OSWorkflow 2.8//EN" "http://www.opensymphony.com/osworkflow/workflow_2_8.dtd
就会去读取http://www.opensymphony.com/osworkflow/workflow_2_8.dtd 这里的dtd文件来验证,但是因为网络是不通的所以就会报socket错误。
四、解决办法
1,最开始查看jdom api发现了这样一个方法
builder.setValidation(false);
这样可以让jdom不做验证,但是结果依然出问题,查了一下原因,说虽然不验证但是还是会下载
2,参照jdom网站的FAQ http://www.jdom.org/docs/faq.html#a0100
这是原文内容
里边教我们定义个类
通过builder.setEntityResolver(new NoOpEntityResolver())方法来隐蔽起dtd验证器。这样就不会出错了。试了一下确实没问题了。但要知道xml没有dtd验证是不好的,我们是否能让它使用本地dtd验证呢。例如本文的oswork
我把验证文件workflow_2_8.dtd拷贝到本地,能否验证的时候用本地的呢?
3,用本地dtd验证
方法有两种
方法一、更改xml中的doctype声明,但是一般情况下更改这个是不好的。更改后就不是标准的了。
方法二、验证期替换
public Document load(String file) throws JDOMException, IOException {
try {
SAXBuilder sax = new SAXBuilder();
sax.setValidation(false);
sax.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId,String systemId) throws SAXException, IOException {
/*InputSource is = new InputSource(new FileInputStream(System.getProperty("user.dir")+"//web-app_2_3.dtd"));
is.setPublicId(publicId);
is.setSystemId(systemId);
return is;
*/
return new InputSource(new FileInputStream(""));
}
});
return sax.build(file);
} catch ( Exception e ) {
e.printStackTrace();
return null;
}
}
http://blog.csdn.net/youlianying/article/details/5908335
jdom dom4j解析xml不对dtd doctype进行验证(转)
标签:
原文地址:http://www.cnblogs.com/softidea/p/4260462.html