Java, xml, XSLT: Prevent DTD-Validation

前端 未结 5 1340
醉酒成梦
醉酒成梦 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:37

    You need to be using javax.xml.parsers.DocumentBuilderFactory

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource src = new InputSource("http://de.wikipedia.org/wiki/Right_Livelihood_Award")
    Document xmlDocument = builder.parse(src.getByteStream());
    DOMSource source = new DOMSource(xmlDocument);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer(xsltSource);
    transformer.transform(source, new StreamResult(System.out));
    

提交回复
热议问题