问题解决org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
问题解决org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
参考自以下两篇文章:
问题1: https://www.iteye.com/blog/zhouhaitao-1168141.
问题2: https://www.iteye.com/topic/97841.
解析xml时候,出现如下报错:
报错1:org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
详细报错
报错2:
/Users/…/…/coverage.xml
org.xml.sax.SAXNotRecognizedException: 无法识别功能 ‘http://cobertura.sourceforge.net/xml/coverage-04.dtd’。
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.getFeature(AbstractSAXParser.java:1826)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.setFeature(SAXParserImpl.java:469)
at org.dom4j.io.SAXReader.setFeature(SAXReader.java:218)
at formattingXml.formattingXml.xmlToString(formattingXml.java:37)
at formattingXml.formattingXml.main(formattingXml.java:26)
解决思路:
报错1解决:
是因为解析的xml中有url,解析时候会访问拒绝,所以报错,所以要用到
SAXReader saxReader = new SAXReader();
saxReader.setFeature("http://cobertura.sourceforge.net/xml/coverage-04.dtd", false);
然后会出现报错2;
报错2解决:
不知道为啥,多谢那位大神了。
关于更多的 Feature 请参考
com.sun.org.apache.xerces.internal.impl.Constants.
public static final String XERCES_FEATURE_PREFIX = "http://cobertura.sourceforge.net";
public static final String LOAD_EXTERNAL_DTD_FEATURE = "xml/coverage-04.dtd";
SAXReader saxReader = new SAXReader();
//http://cobertura.sourceforge.net/xml/coverage-04.dtd
saxReader.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false);