Arun-

This is actually a parser-level issue, but there are a few solutions.

First, probably the safest approach is to write your own
EntityResolver that will feed the parser the DTDs required from a
convenient location (often a jar file).  For an example of how to
implement one, look at org.exolab.castor.util.DTDResolver.  Once you
have one, simply call setEntityResolver on the Unmarshaller object to
have the parser use your EntityResolver.

The second option is to disable DTD fetching in the parser.  There
isn't a convenient way to do this through Castor, but you can create
your own parser, set the correct properties, and then use it in
conjunction with Castor to unmarshal the XML.  For example, using the
Xerces parser (haven't tested this so might be a little rough):

SAXParserFactory factor = SAXParserFactory.newInstance();
factory.setValidating( false ); // If validating is on, you must supply the DTD
XMLReader xmlReader = factory.newSAXParser().getXMLReader();
xmlReader.setFeature(
      "http://apache.org/xml/features/nonvalidating/load-external-dtd";, false );
Unmarshaller um1 = new Unmarshaller();
UnmarshalHandler handler = um1.createHandler();
xmlReader.setContentHandler( handler );
xmlReader.setErrorHandler( handler );
xmlReader.parse( input );
Object rootObject = handler.getObject();

Let me know how either option goes as we are currently developing
documentation related to this issue.

Hope that helps,
Stephen


On 3/14/06, Arunkumar Soundararajan <[EMAIL PROTECTED]> wrote:
> Hi
>
> I have an XML which requires parsing, but this XML uses a dtd which is
> specific to the XML and since castor while unmarshalling is not able to
> recoginise this - throws an error. Can you please let me know how to
> "ignore unnecessary DTD's"?
>
> Arun
>
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>

Reply via email to