Unfortunately, setting xml.catalog.files does not affect the factory parser. Ideally, this should, of course, but the only way to use the resolver is to somehow add a method that delegates permission to the directory resolver in the handler that uses the SAX analyzer.
If you already use the SAX parser, this is pretty easy:
final CatalogResolver catalogResolver = new CatalogResolver(); DefaultHandler handler = new DefaultHandler() { public InputSource resolveEntity (String publicId, String systemId) { return catalogResolver.resolveEntity(publicId, systemId); } public void startElement(String namespaceURI, String lname, String qname, Attributes attrs) {
Otherwise, you need to find out if you can provide your own entity recognizer. Using javax.xml.parsers.DocumentBuilder you can. With the scala.xml.XML object you cannot, but you can use subterfuge:
val res = new com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver val loader = new factory.XMLLoader[Elem] { override def adapter = new parsing.NoBindingFactoryAdapter() { override def resolveEntity(publicId: String, systemId: String) = { res.resolveEntity(publicId, systemId) } } } val doc = loader.load(new URL("http://horstmann.com/index.html"))enter code here
cayhorstmann
source share