在代码中使用:

1:  DocumentHelper.parseText

2:

SAXReader reader = new SAXReader();

Document extdocument = reader.read(new File(extMapperPackagePath));

经过检测每次加载3KB文件的xml耗时1秒钟。性能极慢。经过很久终于找到原因,原来是验证xmlDTD文件导致的。

 

解决办法:跳过DTD验证。

步骤1:创建类

package com.my.common.generator.myplugins;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

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

}
View Code

相关文章:

  • 2021-07-22
  • 2021-10-14
  • 2022-12-23
猜你喜欢
  • 2022-01-06
  • 2022-02-11
  • 2021-12-04
  • 2021-10-19
  • 2021-04-27
  • 2021-11-24
  • 2021-09-18
相关资源
相似解决方案