"Pavel" <olgt-> wrote in message
news: om...
> Greetings to all -
>
> I'm having a problem processing xml with relative dtd URI specified
> using XSLT:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <!DOCTYPE mydoc SYSTEM "my.dtd">
> <mydoc>
> ...
> </mydoc>
>
> I do not have a control over the original xml but I have my.dtd in the
> app classpath. I'm getting the TransformerException: Relative URI
> "my.dtd" can not be resolved without a base URI.
>
> How do I tell to javax.xml.transform.Transformer where to find the dtd
> file w/out specifying the base URI (or any other modifications of the
> original xml)?
>
Hi Pavel,
Setting a custom URIResolver on the transformer won't help, since this URI
resolver is used only for resolving relative URI's passed to the XSLT
document function.
What you need to do instead is, on an XMLReader that is reading the XML
file, call the setEntityResolver method to set a custom EntityResolver.
Your custom EntityResolver needs to provide a resolveEntity method that will
do the job of substituting the absolute URL for the relative URL, see the
example of an EntityResolver in the java api docs.
So, instead of using a StreamSource to read the document, create an
XMLReader using an XMLReaderFactory, and set the EntityResolver to your
custom resolver, also create an InputSource object with the file URL, and
finally create a SAXSource object with the XMLReader and the InputSource.
That should do it.
Regards,
Daniel Parker
http://servingxml.sourceforge.net/