DTD download error while parsing XHTML document in XOM

后端 未结 2 1350
醉梦人生
醉梦人生 2020-12-17 02:25

I am trying to parse an HTML document with the doctype declared to use the transitional dtd as follows:

相关标签:
2条回答
  • 2020-12-17 02:26

    Taking a quick look at the javadoc for Builder, I guess you could provide an EntityResolver via the constructor that takes a XMLReader. I would avoid letting the parser download files from the internet where possible.

    0 讨论(0)
  • 2020-12-17 02:48

    This solves the problem:

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setValidating(false);
                factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
                Document document = factory.newDocumentBuilder().parse(is);
    
    0 讨论(0)
提交回复
热议问题