Hi Derrick,

On Sat, 2004-04-17 at 07:13, Koes, Derrick wrote:
> I'm using a home grown serializer (DOMWriter) to write my xml to a
> file.  I'm curious as to what other people are using.

As far as I know, there are two options.
[note: all code below is just a "rough" outline]

The "portable" option is to use JAXP.
  import javax.xml.tranform.*;

  TransformerFactory factory = ...
  Transformer t = factory.newTransformer(); // identity transform
  DOMSource source = new DOMSource(mydocument);
  StreamResult result = new StreamResult(new File("foo.xml"));
  t.transform(source, result);

Class javax.xml.transform.OutputKeys allows tweaking of the output
format.

The alternative is to use the org.apache.xml.serialize.XMLSerializer
class (shipped with xerces). The HTMLSerializer in this package was
deprecated in xerces 2.6.2, so I guess the XMLSerializer will face the
same fate soon (in favour of the xslt-based solution). However for those
of us on pre-java-1.4 with apps that use xml but not xslt and do not
wish to ship an entire xslt engine just to do serialization, it is still
a good option. 


Regards,

Simon


Reply via email to