RE: Maybe someone can tell us

> why the DOM version 1 didn't specify a means of getting the
> actual XML out
> of the DOM document.  I'm not really talking about loading and saving
> files, but rather just getting the contents of the DOM doc as a
> big string
> at least.
>
> Does someone have a historical perspective on this?  I'm trying to
> implement some XML functionality with Xerces and I'm frustrated with the
> hassle of writing reams of code just to get the DOM into usable XML.

I can't provide you with any history. However, if you can save to a file,
you can also save to a String? You didn't mention whether you use Xerces-C
or Xerces-J? With Xerces-J it is possible to do this without reams of code:

----------------------------------------------
import org.apache.xml.serialize.XMLSerializer;
import java.io.StringWriter;
...
Document document = ...;

StringWriter writer = new StringWriter();
XMLSerializer serializer = new XMLSerializer();
serializer.setOutputCharStream(writer);
serializer.serialize(document);
String serializedXML = writer.toString();

System.out.println(serializedXML);
----------------------------------------------

With future Load/Save implementations, you could of course create a similar
construction.


Hope this helps,

--Sander.

Received on Wednesday, 13 June 2001 03:33:23 UTC