Creating
XML with DTD can be done using Java in many ways. One of the easiest
ways to do that is to serialize the data to a file output stream. You
can do this by using a statement like,
_______________________________________________
_______________________________________________
PrintWriter
out = new PrintWriter(new FileOutputStream("urfile.xml"));
In the
above statement you can create an XML file 'urfile.xml' by using the
FileOutputStream and creating a new PrintWriter object. Once you create
this object it is straightforward to use the statement using out.println();
to generate any type of output you want to your XML file.
However
the XML file that is generated with the DTD using this method might
not a valid XML file. The tag to include the DTD within the XML file
also has to written to the stream using such statements.
The other
combinations that can be used to create XML with DTD are to use DOM
and Xerces, SAX and Xerces, JAXP and DOM, or JAXP and SAX. Check the
following URL
http://www.javazoom.net/services/newsletter/xmlgeneration.html
for some sample code by using the straightforward PrintWriter method.