"Pramodh Peddi" <[EMAIL PROTECTED]> wrote on 12/17/2003 11:28:38 AM:

> Hi,
> I posted a requestion and I did not get any response back. I thought it
was
> difficult to understand what I asked in my previous post.
> Here is a better way of explaining my question(s):
> I have an xml source, to be transformed, which has a relative DTD
reference
> (just the dtd filename is specified), like:
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE CONTENT_FEED SYSTEM "myDTD.dtd">
> <root>
> ......
> ....
> </root>
>
> The problem is myDTD.dtd is available NEITHER in the classpath NOR where
the
> class file is located. But, it is available in a http-accessible
location,
> like: http://myserver.com/dtd/myDTD.dtd.
>
> So, I would like to tell the parser to consider
> "http://myserver.com/dtd/myDTD.dtd"; instead of myDTD.dtd to validate the
> source xml. (I know thats a stupid way of referring to a DTD, but thats
the
> customer's feed and they cannot change it).

http://xml.apache.org/xalan-j/apidocs/org/xml/sax/EntityResolver.html has
an example similar to what you want to do.

In the class that implements EntityResolver (your DTDResolver), you want
the method

   public InputSource resolveEntity (String publicId, String systemId)
   {
     if (systemId.equals("myDTD.dtd")) {
              // return a special input source
            return (new URL("http://myserver.com/dtd/myDTD.dtd";
)).openStream();
     } else {
              // use the default behaviour
       return null;
     }
   }

Reply via email to