aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to change JDOM Document into String? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to change JDOM Document into String?" Watch "How to change JDOM Document into String?" New topic
Author

How to change JDOM Document into String?

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Hello, guys:
I am struggling to do the above, how
can I achieve that?
regards,
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Have you tried org.jdom.Document.toString() ?


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Originally posted by Valentin Crettaz:
Have you tried org.jdom.Document.toString() ?

Thanks, Valentin. toString does not work, only gives you
root element and ns.
I figured it out, the follwoing will work:
StringWriter writer = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer tran = tf.newTransformer();
Source src = new DOMSource(doc);
Result res = new StreamResult(writer);
tran.transform(src, res);
String xml = writer.toString();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to change JDOM Document into String?