dom4j本地校验DTD
如果XML中存在
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
这种语句,说明要进行校验。
如果校验则会连接网络,这样做会很慢的。我们可以设置成校验本地的DTD,那么就设置个解释器到SAXReader,代码如下所示:
EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if ( publicId.equals( "-//Acme//DTD Foo 1.2//EN" ) ) { InputStream in = getClass().getResourceAsStream( "/com/acme/foo.dtd" ); return new InputSource( in ); } return null; } }; SAXReader reader = new SAXReader(); reader.setEntityResolver( resolver ); Document document = reader.read(new File(fileName));
这样就能实现本地校验了。
相关推荐
liaoxuewu 2020-04-10
ELEMENTS爱乐冬雨 2019-10-21
Yakamoz 2014-09-05
kenvie 2017-10-19
DodderB 2017-10-19
kenvie 2013-06-24
HiramYong 2013-04-14
Yakamoz 2014-09-05
realhero 2014-04-30
kenvie 2012-06-13
hongyuancao 2011-11-14
katelynlily 2012-09-07
Yakamoz 2012-06-20
道 2012-06-13
abchywabc 2012-04-16
kenvie 2012-03-06