好的,事实证明该parse()
方法会覆盖任何先前设置的实体解析器,并将处理程序传递给parse方法.以下代码应该有效:
javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance(); factory.setValidating(false); javax.xml.parsers.SAXParser parser = factory.newSAXParser(); parser.parse(new java.io.File("x.xml"), new org.xml.sax.helpers.DefaultHandler(){ public org.xml.sax.InputSource resolveEntity(String publicId, String systemId) throws org.xml.sax.SAXException, java.io.IOException { System.out.println("Ignoring: " + publicId + ", " + systemId); return new org.xml.sax.InputSource(new java.io.StringReader("")); } });