[jdom-interest] insert a new line after the root

Jason Hunter jhunter at servlets.com
Sat Sep 14 08:28:21 PDT 2002


You're adding elements but no whitespace, so that's what you see on
output.  You can either add whitespace or ask XMLOutputter to do it for
you.

outp.setNewlines(true);
outp.setIndent("  ");

-jh-

TAZ0789 at aol.com wrote:
> 
> Hi,
> 
>    I'm writing a program that can help generate all the source and
> deployment descriptor for the EJB 2.0 CMP Beans.  I'm writing the part
> where I need to generate the xml files.  When I add children to the
> root, it's funny to see how the first child is aligned with the parent
> while all the other children has their own line.  Is there a way to
> insert a new line after the parent, so that the first child will have
> its own line?  Here's my source and resulting xml:
> 
> Source:
> 
> Element root = new Element("GREETING");
> root.setText("Hello JDOM!");
> 
> Element child = new Element("KID");
> child.setText("child 1");
> 
> Element child1 = new Element("KID1");
> child1.setText("child 2");
> 
> root.addContent(child);
> root.addContent(child1);
> 
> Document doc = new Document(root);
> 
> Resulting XML:
> 
> <GREETING>Hello JDOM!<KID>child 1</KID>
>        <KID1>child 2</KID2>
> </GREETING>
> 
> Please help.  Thanks.





More information about the jdom-interest mailing list