If you wantd, raise a new issue at

http://jira.codehaus.org/browse/CASTOR

and ask us to add a new FAQ entry.

Werner

PS Maybe we should add a HOW-TO as well, and/or add this pitfall to an existing one.

Corcuera,Ron wrote:
Sorry about that. That was inconsiderate of me. I was using the static
method
        Unmarshaller.unmarshal(java.lang.Class c, java.io.Reader reader)
This was causing the problem. I changed that by instantiating the
Unmarshaller with a given class:
        Unmarshaller um1 = new Unmarshaller(MyMessage.class);
and then used:
        um1.unmarshal(java.io.Reader reader).
MyResolver is then called properly.

Thank you,
Ron

-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 01, 2008 3:19 PM
To: [email protected]
Subject: Re: [castor-user] RE: Castor unmarshaller to fetch DTD locally
instead of DTD stated in XML file

Which happens to be (for the reading benefit of other users) ?

Werner

Corcuera,Ron wrote:
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



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to