You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Craig Collings <cr...@cabusiness.co.nz> on 2001/12/02 20:07:09 UTC
RE: XML output of DOM
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:ishabtay@netvision.net.il]
Sent: Saturday, 1 December 2001 10:53 a.m.
To: xerces-j-user@xml.apache.org
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" <DV...@SECTORBASE.COM>
To: <xe...@xml.apache.org>
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:tmcnulty@datadesk.com]
> Sent: Friday, November 30, 2001 11:50
> To: xerces-j-user@xml.apache.org
> 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: tmcnulty@datadesk.com
> Web: www.datadesk.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org