[jdom-interest] Turning off DTD validation within JDOMSource
Laurent Bihanic
laurent.bihanic at atosorigin.com
Tue May 14 05:20:26 PDT 2002
Hi Gary,
Good news: SAXOutputter has been patched as you suggested. So, if you download
the latest revision from CVS, the following code should prevent DTD parsing:
JDOMSource src = new JDOMSource(doc);
src.getXMLReader().setFeature("http://xml.org/sax/features/validation",
false);
Hope this helps,
Laurent
Laurent Bihanic wrote:
>
> Hi Gary,
>
> (Sorry for the late response.)
>
> The problem you're probably having here is that you probably set a
> DocType on your JDOM documents. To behave as close as possible to a real
> XML parser, JDOMSource relies on SAXOutputter that tries (when the XSLT
> transformer requests) to provide the information present in the DTD. For
> that, it runs an XML parser on the DocType to generate DTD events
> towards the XSLT processor.
>
> "When the XSLT transformer requests" actually means when the XSLT
> transformer registers a LexicalHandler and/or a DeclHandler on the
> JDOMSource-provided XMLReader, i.e. SAXOutputter.
>
> There's currently no way to configure JDOMSource or SAXOutputter not to
> try to parse the DTD. But you may try one of the following:
> - Prevent the XSLT processor to register the listed handlers (not
> possible, I think!)
> - Reset the DocType of the document before calling transform()
> - Hack JDOMSource/SAXOutputter to add a flag to prevent DTD parsing
>
> For the last option, have a look at the method dtdEvents() in SAXOutputter.
>
> Laurent
>
>
> Gary Lawrence Murphy wrote:
>
>>>>>>> "G" == Gary Lawrence Murphy <garym at canada.com> writes:
>>>>>>
>>>>>>
>>
>> G> Transformer xslt = TransformerFactory.newInstance()
>> G> .newTransformer(new StreamSource(xsl)); xslt.transform(new
>> G> JDOMSource(dom), newdom);
>>
>> G> Is there some way to tell the JDOMSource (or the
>> G> TransformerImpl) that it should ignore the DTD?
>>
>> According to the API docs, the following should work, but it doesn't:
>>
>> JDOMSource jds = new JDOMSource(dom);
>> jds.getXMLReader().setFeature(
>> "http://xml.org/sax/features/validation",
>> false); // ignore DTD
>>
>> What is the correct way to do this?
>>
More information about the jdom-interest
mailing list