Java, xml, XSLT: Prevent DTD-Validation

前端 未结 5 1339
醉酒成梦
醉酒成梦 2020-12-16 06:28

I use the Java (6) XML-Api to apply a xslt transformation on a html-document from the web. This document is wellformed xhtml and so contains a valid DTD-Spec (

5条回答
  •  无人及你
    2020-12-16 06:53

    Try setting a feature in your DocumentBuilderFactory:

    URL url = new URL(urlString);
    InputStream is = url.openStream();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    DocumentBuilder db;
    db = dbf.newDocumentBuilder();
    Document result = db.parse(is);
    

    Right now I'm experiencing the same problems inside XSLT(2) when calling the document function to analyse external XHTML-pages.

提交回复
热议问题