This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
I am trying to transform some XML files that have DTDs specified. Unfortunately I do not always have Internet access and so I get exceptions like connection timeout and unknown host. Is there a way to prevent the parser from even attempting to retrieve the DTD? I am using net.sf.saxon.TransformerFactoryImpl to create my transformer instance, any help on how to do this would be greatly appreciated.
Nope. Failing to use the DTD could change the meaning of the document, or even make it not well-formed in some cases, so parsers don't give you that option. But there is a way to provide a local version of the DTD to the parser. Check out the setEntityResolver() method.
Joined: Jan 09, 2006
I am not able to find any documentation on that method and it does not appear to be a method on the factory transformer instance, of configuration of the factory. Do you know of an example that I could look at?
When you pass on the Source to the transform() method, it can be SAXSource, it can be DOMSource, it can be StreamSource... If you want to have more control on what to pass, you would bet on using SAXSource or DOMSource. To construct them, XMLReader and DocumentBuilder classes can be setup with custom EntityResolver() and that is where you set the re-direction or customizing the handling. In the case you simply want to "kill" the dtd fetching, you can make it return an InputSource without any content at all.
Let x be your XMLReader or DocumentBuilder variable, this is how it is done: