解决办法可以参见这位老兄的博客:[url]http://tailsherry.iteye.com/blog/98111[/url]
对第二种方法补充两个小分支:
1.直接写一内部类,代码如下
使用时,加上代码:
这样也能通过。
2.可参考hibernate的处理方式来实现EntityResolver。见org.hibernate.util.DTDEntityResolver。这里贴上它的resolveEntity()方法。
对第二种方法补充两个小分支:
1.直接写一内部类,代码如下
class NoOpEntityResolver implements EntityResolver {
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(new StringBufferInputStream(""));
}
}
使用时,加上代码:
xmlReader.setEntityResolver(new NoOpEntityResolver());
这样也能通过。
2.可参考hibernate的处理方式来实现EntityResolver。见org.hibernate.util.DTDEntityResolver。这里贴上它的resolveEntity()方法。
public InputSource resolveEntity(String publicId, String systemId) {
if ( systemId != null ) {
log.debug( "trying to resolve system-id [" + systemId + "]" );
if ( systemId.startsWith( HIBERNATE_NAMESPACE ) ) {
log.debug( "recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/" );
String path = "org/hibernate/" + systemId.substring( HIBERNATE_NAMESPACE.length() );
InputStream dtdStream = resolveInHibernateNamespace( path );
if ( dtdStream == null ) {
log.debug( "unable to locate [" + systemId + "] on classpath" );
if ( systemId.substring( HIBERNATE_NAMESPACE.length() ).indexOf( "2.0" ) > -1 ) {
log.error( "Don't use old DTDs, read the Hibernate 3.x Migration Guide!" );
}
}
else {
log.debug( "located [" + systemId + "] in classpath" );
InputSource source = new InputSource( dtdStream );
source.setPublicId( publicId );
source.setSystemId( systemId );
return source;
}
}
else if ( systemId.startsWith( USER_NAMESPACE ) ) {
log.debug( "recognized local namespace; attempting to resolve on classpath" );
String path = systemId.substring( USER_NAMESPACE.length() );
InputStream stream = resolveInLocalNamespace( path );
if ( stream == null ) {
log.debug( "unable to locate [" + systemId + "] on classpath" );
}
else {
log.debug( "located [" + systemId + "] in classpath" );
InputSource source = new InputSource( stream );
source.setPublicId( publicId );
source.setSystemId( systemId );
return source;
}
}
}
// use default behavior
return null;
}