• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stop Xerces from requesting DTD

 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
g tsuji
Ranch Hand
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>it does not appear to be a method on the factory transformer instance, of configuration of the factory
Sure it is not. But is it that difficult to google out what sort of handling it is meant for?

This is a short hand-on:
http://www.ibm.com/developerworks/library/x-tipent/index.html

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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic