W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2001

Re: Writing DOM Object to XML

From: Joseph Kesselman <keshlam@us.ibm.com>
Date: Mon, 7 May 2001 17:34:59 -0400
To: "'www-dom@w3.org'" <www-dom@w3.org>
Message-ID: <OFD4480A95.B4230653-ON85256A45.0075EB06@pok.ibm.com>

>    I have an XML file which I read into a DOM and then I do some
>transformations. How do I write it back to xml?

This isn't standardized yet, though DOM Level 3 is working on a proposal
for a Load/Save API which would address this (for those DOMs which
implement it).

For now, the answer is that you need to find or write code which reads the
data out of the DOM and writes it out as XML syntax. Most XML parsers come
with at least a basic version of this -- check the documentation for your
preferred parser package, and/or its sample programs.

In the Apache Xerces-J parser, to take one example, there is a package of
"serialization" classes that provide this function. Since it adheres pretty
strictly to the standard DOM and SAX APIs, you could use that code with
most other Java DOMs, and since it's open souce you could port it to other
languages. (In fact, if you port it to C++ and donate the result back to
Apache you're likely to get a standing ovation; Xerces-C users have been
eagerly waiting for someone to find time to tackle that project, and have
been using the primitive-but-almost-adequate-for-most-purposes DOMPrint
sample program as a stopgap solution.)


______________________________________
Joe Kesselman  / IBM Research
Received on Monday, 7 May 2001 17:35:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT