How to add internal DTD subset to the newly created xml file using javax.xml

Post here questions and problems related to oXygen frameworks/document types.
vishwavaranasi
Posts: 99
Joined: Fri Feb 28, 2020 4:02 pm

How to add internal DTD subset to the newly created xml file using javax.xml

Post by vishwavaranasi »

Hello Team , I know this is a general java question

am using the API

import javax.xml.parsers.DocumentBuilder;

import javax.xml.transform.Transformer;

to create a xml

I am trying to add the DOCTYPE and DTD declaration as below

Code: Select all

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        
        transformer.setOutputProperty(
                  OutputKeys.DOCTYPE_PUBLIC, "-//XXX//DTD XXX YYY XXX//EN");
        transformer.setOutputProperty(
                  OutputKeys.DOCTYPE_SYSTEM, "XXX.dtd");
but my final doctype declaration should be

Code: Select all

DOCTYPE XXX PUBLIC "-//XXX//DTD XXX YYY XXX//EN" "XXX.dtd"[]
I want add at the end an empty internal subset [] ..how to do this in java ?
Thanks,
vishwa
Radu
Posts: 8283
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to add internal DTD subset to the newly created xml file using javax.xml

Post by Radu »

Hi,
You cannot set an internal DTD subset just by setting properties on the transformer.
You could try to force outputting the DOCTYPE along with its subset directly from the XSLT template:

Code: Select all

 <xsl:template match="/">
        <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE abc[&lt;!ENTITY ent 'test'>]></xsl:text>
or as a workaround after applying the XSLT and producing the content, apply some regular expression on the content and replace the empty DOCTYPE string with a DOCTYPE which contains an internal subset.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
vishwavaranasi
Posts: 99
Joined: Fri Feb 28, 2020 4:02 pm

Re: How to add internal DTD subset to the newly created xml file using javax.xml

Post by vishwavaranasi »

Thanks Radu :)
Thanks,
vishwa
Post Reply