[jdom-interest] writing XML to a String
trebor.a.rude at lmco.com
trebor.a.rude at lmco.com
Wed Aug 30 07:03:46 PDT 2000
Here's how I do it currently (against the most recent CVS):
ByteArrayOutputStream byteRep = new ByteArrayOutputStream();
XMLOutputter docWriter = new XMLOutputter("", false);
xmlWriter.output(document, byteRep);
String stringRep = byteRep.toString();
This is untested as yet, but it should work. Elliote mentioned a few days
ago that eventually,
it's going to be much simpler, like this:
String stringRep = xmlWriter.serialize(document);
Unfortunately, that functionality isn't there yet, and I haven't seen any
pointers to where the patch might be.
Trebor A. Rude
trebor.a.rude at lmco.com
> -----Original Message-----
> From: Cameron Smith [SMTP:cameron.smith at entranet.co.uk]
> Sent: Wednesday, August 30, 2000 6:56 AM
> To: 'jdom-interest at jdom.org'
> Subject: [jdom-interest] writing XML to a String
>
> I wanted to use XMLOutputter to output a Document to a
> String/StringBuffer,
> which would then be wrapped up in a larger message by another system
> component and sent off somewhere.
>
> Unfortunately output() can only use a print stream, and java.io only
> provides a StringWriter and no OutputStream -> Writer class. I have a
> feeling I'm missing something obvious - anyone have a suggestion?
>
> Alternatively, does the latest cvs build now have an output(Writer)
> method?
> (I know the javadocs aren't totally in sync with builds).
>
More information about the jdom-interest
mailing list