java 代码 SAXReader saxReader = new SAXReader();
saxReader.setValidation(false);
saxReader.setIncludeInternalDTDDeclarations(false);
saxReader.setIncludeExternalDTDDeclarations(false);
Document doc = saxReader.read(new File(fileName));
System.out.println(doc.asXML());
无效
网上找了个
public class IgnoreDTDEntityResolver implements EntityResolver
{
public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException,
java.io.IOException
{
if (systemId.equals( "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd ")
|| systemId.equals( "http://java.sun.com/dtd/ejb-jar_2_0.dtd ")
|| systemId.equals( "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd "))
return new InputSource(new ByteArrayInputStream( " <?xml version=’1.0′ encoding=’UTF-8′?> ".getBytes()));
else
return null;
}
}
依然无效
老外的
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.omg.CORBA.portable.InputStream;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class IgnoreDTDEntityResolver implements EntityResolver
{
public InputSource resolveEntity(String publicId, String systemId) {
if ( publicId.equals( "-//Acme//DTD Foo 1.2//EN " ) ) {
InputStream in = (InputStream) getClass().getResourceAsStream( "hibernate.dtd ");
return new InputSource( in );
}
return null;
}
}