"dom4j, dtd, EntityResolver, 未找到外部实体, 慢"
Using dom4j to read xml file, it always resolve external or internal DTDs, then it makes reading slow or raise exception. I've found a way to resolve this.
Reading codes:
SAXReader saxReader = new SAXReader(false);
NullEntityResolver resolver = new NullEntityResolver();
saxReader.setEntityResolver(resolver);
Document document = saxReader.read(xmlFileName);
EntityResolver codes:
class NullEntityResolver implements EntityResolver {
static String emptyDtd = "";
static ByteArrayInputStream byteIs = new ByteArrayInputStream(emptyDtd.getBytes());
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(byteIs);
}
}