原来
SAXReader reader = new SAXReader();
修改后
public class IgnoreDTDEntityResolver implements EntityResolver {
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
}
}
SAXReader reader;
public SAXReader getReader(){
if (reader == null){
reader = new SAXReader();
reader.setEntityResolver(new IgnoreDTDEntityResolver());
}
return reader;
}
需要使用 reader 是,调用 getReader , 而不是自己 new 一个,这样既成功的忽略了读取 xml 是的文件头检查