31

How do I to convert an org.jdom.Document to a String in Java?

james.garriss
  • 12,959
  • 7
  • 83
  • 96
Aravind
  • 2,188
  • 4
  • 24
  • 28

3 Answers3

59
new XMLOutputter().outputString(doc);
Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
15

I got the answer myself

XMLOutputter xmOut = new XMLOutputter(); 
System.out.println("----" + xmOut.outputString(doc));
Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
Aravind
  • 2,188
  • 4
  • 24
  • 28
0

You can as well do like this with StringWriter

    StringWriter writer = new StringWriter();
    new XMLOutputter().output(doc, writer);
    System.out.println(writer.toString());
mwangox
  • 389
  • 5
  • 4