Instead of a fake converter, the following code snippet instructs the parser to really ignore the external DTD from the DOCTYPE declaration:
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; (...) DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); f.setValidating(false); f.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder builder = f.newDocumentBuilder(); Document document = builder.parse( ... )
source share