Do not resolve DTD files when dom4j read xml file
发布日期:2022-02-19 23:50:34 浏览次数:34 分类:技术文章

本文共 725 字,大约阅读时间需要 2 分钟。

"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);
    }
}

 

转载地址:https://blog.csdn.net/lessoft/article/details/1659579 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:用Hibernate+Struts做东西,感觉真是舒服(有内容)
下一篇:ORACLE SQL 优化策略-1

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月13日 17时24分33秒