[jdom-interest] newbie

Mark C. Stafford obbyyoyo at gmail.com
Fri Oct 29 13:50:13 PDT 2004

On 29 Oct 2004 19:20:49 -0000, pamarti  srikiran
<psrikiran at rediffmail.com> wrote:
> Hi I recently downloaded jdom 1.0 and tried to use it. I m unable
> to get the newline to be printed in the output xml file.
> Im getting the following output
> <sri>hi</sri>
> instead of
> <sri>
> hi
> </sri>
> can anybody tell me how to do this. i have examples that use
> oldversion of jdom. help is greatly appreciated
> thanks
> -sri

I think that there were too few items to trigger proper prettiness, so
I added one. Is this what you want?

import org.jdom.*;
import org.jdom.output.*;
class foo {
  public static void main(String mainArgs[]) {
    Element foo1 = new Element("stuff");
    Element foo2 = new Element("sri");
    Element foo3 = (Element)foo1.clone();
    Format f = Format.getPrettyFormat();
    Format r = Format.getRawFormat();
    r.setOmitDeclaration(true); // leaves out <?xml version="1.0"
    XMLOutputter a = new XMLOutputter(f);
    XMLOutputter b = new XMLOutputter(r);
    String bar = a.outputString(new Document(foo1));
    String zee= b.outputString(new Document(foo3));
      <?xml version="1.0" encoding="UTF-8"?>

More information about the jdom-interest mailing list