Richard, Thanx for the quick reply. I am doing almost similar to what the
xalan site says. But, I have some more information this time.
The application is running on JBoss Appserver. As you know, the source xml
has DTD reference called "myDTD.dtd". The application is throwing an error
saying it is looking for the SystemID "file:///C:/jboss/bin/myDTD.dtd".

And when i say:
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
System.out.println("DOES NOT MATCH THE DTD STRING");
        return null;
      }
    }

it is printing "DOES NOT MATCH THE DTD STRING", because it is looking for
the systemId "file:///C:/jboss/bin/myDTD.dtd". And earlier, i did not put
any "if" stmt and was sending the inputSource of
"http://myserver.com/dtd/myDTD.dtd"; no matter what. In this case, it was not
throwing an error, but was giving empty string out of the transformation
(the transformed string just had the xml header, and with wrong encoding).

For extra information, i am setting the systemId to "myDTD.dtd" explicitly
by calling source.setSystemId("myDTD.dtd"); where source is instance of
SAXSource.

I really do not know whats happening.

Hope I'll find some help to fix this problem.

Pramodh.

----- Original Message ----- 
From: "Richard Cao" <[EMAIL PROTECTED]>
To: "Pramodh Peddi" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, December 17, 2003 12:01 PM
Subject: Re: resolving DTDs while transforming


>
>
>
>
> "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