• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stop Xerces from requesting DTD

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic