And for my two cents worth, I would do it like this:
import org.apache.xml.serialize.*;
Document document; // from somewhere
...
OutputFormat format = new OutputFormat(document, "UTF-8", true);
StringWriter writer = new StringWriter();
XMLSerializer serial = new XMLSerializer(writer, format);
serial.asDOMSerializer();
serial.serialize(document);
writer.close();
String result = writer.toString();
-----Original Message-----
From: Isaac S. [mailto:[EMAIL PROTECTED]
Sent: Saturday, 1 December 2001 10:53 a.m.
To: [EMAIL PROTECTED]
Subject: Re: XML output of DOM
Well, although this method works, it's non-standard.
Explicitly using Xalan&Xerces' abilities is not considered as "standard".
The correct standard way of outputting a DOM document into a string is using
JAXP's transformation API:
Document myDoc;
// Populate the document
// Now output it as a string.
StringWriter sw = new StringWriter();
(javax.xml.transform.dom.)DOMSource src = new DOMSource(myDoc);
(javax.xml.transform.stream.)StreamResult result = new StreamResult(sw);
(javax.xml.transform.)Transformer t =
TransformerFactory.newInstance().newTransformer();
t.transform(src,result);
// Now, sw.toString() will give you the string representation of the DOM
document.
----- Original Message -----
From: "Voytenko, Dimitry" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, November 30, 2001 9:56 PM
Subject: RE: XML output of DOM
> Hi Tobias,
>
> You may try org.apache.xml.serialize.XMLSerializer class or if you use
> Xalan: org.apache.xalan.serialize.SerializerToXML. You may find a lot of
> utilities for serializing XML browsing these packages.
>
> Thanks,
> Dmitry
>
> -----Original Message-----
> From: Tobias McNulty [mailto:[EMAIL PROTECTED]
> Sent: Friday, November 30, 2001 11:50
> To: [EMAIL PROTECTED]
> Subject: XML output of DOM
>
>
> What is the standard method of taking a DOM Document and outputting
> it as XML (into a String)?
>
> Thanks,
> --
> Tobias McNulty
> Data Description, Inc.
> 840 Hanshaw Road, Suite 9
> Ithaca, NY 14850
> Phone: (607) 257-1000
> E-mail: [EMAIL PROTECTED]
> Web: www.datadesk.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]