当前位置:   article > 正文

java解析xml禁止校验dtd

xml中禁止dtds的解析的做法正确的是

 

  1. import com.sun.org.apache.xerces.internal.impl.Constants;
  2. Constants类在%JAVA_HOME%/jre/lib/rt.jar包中
  3. try{
  4. File file = new File(absoluteDbConfigFile);
  5. Reader reader = new InputStreamReader(new FileInputStream(file),"utf-8");
  6. SAXReader sax = new SAXReader();
  7. sax.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); //设置不需要校验头文件
  8. document = sax.read(reader);
  9. root = document.getRootElement().element("session-factory");
  10. buildCache();
  11. }catch(FileNotFoundException e){
  12. //e.printStackTrace();
  13. }catch(Exception e){
  14. //e.printStackTrace();
  15. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/682130
推荐阅读
相关标签
  

闽ICP备14008679号