[jdom-interest] Passing external URL for DTD reference

Pramodh Peddi peddip at contextmedia.com
Mon Nov 17 12:41:49 PST 2003

I am using Java1.4 for Transformation.
My source xml file has a relative DTD reference (just the file name), but
the file is at a completely different http-accessible location. And I know
the url of that http-accessible location at the time of transforming. What I
am doing is similar to:

<!DOCTYPE EXAMPLE_DTD SYSTEM "xxx.dtd"> is there in the source xml. And
xxx.dtd is at http://myserver.com/xsl/xxx.dtd (the file name in the url can
be different - it can be named as yyy.dtd!). Can I know how to make the
transformer look at this url?

I was passing in this URL to the StreamSource constructor - like
new StreamSource(new StringReader(stylesheetStream),this.dtdURL)
- though I know this is not proper to do. It seems to be resolving the url,
but seem to not really validating the xml stream against the dtd url (I
changed the dtd to make the xml source invalid, but it looks like its
passing through everything without validating it).

Can we achieve this in any other way? I was trying to use EntityResolver
(though I couldn't figure exactly how to do it, I kind of had the idea), but
I think we have to mention the systemID and publicID to the resolver, right?
At that point we don't know the dtd name mentioned in the xml source yet. I
guess we have to do something like:

 public class MyResolver implements EntityResolver {
   public InputSource resolveEntity (String publicId, String systemId)
     if (systemId.equals("xxx.dtd")) {
              // return a special input source
       MyReader reader = new MyReader();
       return new InputSource(http://myserver.com/xsl/xxx.dtd);
     } else {
              // use the default behaviour
       return null;

Here we don't know that the file name would be "xxx.dtd". Can we say return
new InputSource(http://myserver.com/xsl/xxx.dtd); no matter what the xxx.dtd
in the xml source is?

Any help would be greatly appreciated!



More information about the jdom-interest mailing list