zoukankan      html  css  js  c++  java
  • xml解析时禁止网上下载dtd 规格严格

    最近一直在研究xml解析问题,总结了一点小知识,就写下来吧!
    dom解析时,会根据xml文件头的内容网上下载DTD文档,很烦人,速度慢不说,网络如果断了,程序也无法进行了。查了半天资料,终于知道如何解决了。以下为解决方案:

    解决方案一:
    DocumentBuilderFactory builder = DocumentBuilderFactory.newInstance();
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);//
    解决方案二:
    DocumentBuilder parser = builder.newDocumentBuilder();
    EntityResolver resolver = new EntityResolver() {
    public InputSource resolveEntity(String publicId,String systemId)
    throws SAXException, IOException {
    if (publicId.equals("-//Hibernate/Hibernate Configuration DTD//EN")) {
    return new InputSource("../pstn_xml/hibernate-configuration-3.0.dtd");
    }
    return null;
    }
    };
    parser.setEntityResolver(resolver);
  • 相关阅读:
    windows通过Composer安装yii2
    jquery自定义函数
    js 回调
    读取.properties配置文件
    spring @ModelAttribute 注解
    excel导出
    spring定时器
    maven添加自己的jar包到本地仓库
    activeMq 消费者整合spring
    linux操作命令
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2133857.html
Copyright © 2011-2022 走看看