[jdom-interest] How to read a DTD as a resource file?

John L. Webber - jentro AG John.Webber at jentro.com
Fri May 18 01:21:26 PDT 2001


Hi Stepahn,

The easiest way is to have your parser implement
org.xml.sax.EntityResolver, and in the resolveEntity method get your DTD
from the jar file using  getClass().getResourceAsStream(RESOURCE_NAME).
I can send you some sample code if you like.

Regards,

John


stephan.segschneider at snellwilcox.com wrote:
> 
> Hi all
> 
> I need to pack my DTD inside my application and parse a XML file validating
> against this DTD.
> 
> The following code works fine with JDOM:
> 
>    InputStream xmlIS = App.class.getResourceAsStream(xmlFileName);
>    builder.setValidation(validate);
>    builder.setErrorHandler(errorHandler);
>    // Build the JDOM Document
>    doc = builder.build(xmlIS, dtdURL.toString());
> 
> this is OK if the DTD is an external file, but what do I need to do if the DTD
> is packed inside my applications jar file. The AElfred parser for example allows
> somthing like this:
> 

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jentro AG
John L. Webber, Software Development
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Peter-Henlein-Strasse 28-30, 85540 Haar/Munich, Germany
Tel.:  +49 89 462 385 0     (switchboard)
Tel.:  +49 89 462 385 38    (direct)
Fax:   +49 89 462 385 29
mailto:John.Webber at jentro.com
http://www.jentro.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the jdom-interest mailing list