I have resolved the problem. As I suspected, it was some obvious thing
that I was missing.
 
Thank you,
Ron

________________________________

From: Corcuera,Ron 
Sent: Tuesday, April 01, 2008 11:25 AM
To: [email protected]
Subject: Castor unmarshaller to fetch DTD locally instead of DTD stated
in XML file



We use Castor to generate Java files from a DTD file. We use
org.exolab.castor.xml.Unmarshaller to unmarshall incoming XML files.
Currently, Castor, using the SAX parser, fetches the DTD file stated in
the incoming XML file. We would like for our code to fetch it from a
local source instead.

 

After reading some documentation, it seems all I have to do is create a
MyResolver that implements org.xml.sax.EntityResolver. I could then use
the DTDResolver to wrap MyResolver and set the Unmarshaller to use it.
Unfortunately, MyResolver is never called. The parser happily parses
away after it fetches the dtd that is stated in the XML. The solution
seems so easy and straight forward. But, I'm obviously missing
something. Can someone point me in the right direction?

 

Here is a code snippet where I set the EntityResolver in the
Unmarshaller:

 

String xmlRespString = // some xml file

StringReader stringReader = new StringReader(xmlRespString);

try

   {

      Unmarshaller um1 = new Unmarshaller();

      um1.setEntityResolver(new DTDResolver(new MyResolver()));

      msg = (MyMessage) um1.unmarshal(MyMessage.class, stringReader);

   }

...

 

Thank you,

Ron Corcuera

Reply via email to