[jdom-interest] dealing with whitespace when appending elemen ts

Kesav Kumar kesavk at voquette.com
Mon Dec 11 10:18:45 PST 2000

You can use the method setTrimText(true) on your XMLOutputter.  This method
will trim off any white spaces it originally has.  With XMLOutputter("  ",
true) you will get the new indentation of "  ".

Kesav Kumar
Software Engineer
Voquette, Inc.
650 356 3740
mailto:kesavk at voquette.com

-----Original Message-----
From: Neil Burnett [mailto:neil at efc.be]
Sent: Sunday, December 10, 2000 11:59 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] dealing with whitespace when appending elements

I hope this is the right place to ask this question - its mind-numbingly

I have successfully developed an application which:

1	reads an xml file to a Document
2	creates a new Element with children
3	adds the new Element to the end of the Document
4	writes the new Document back to disk

Great! Except that if I want to preserve the pretty formatting (indentation
and whitespace), I find the XMLOutputter("  ",true) accumulates the
whitespace like this:


		<thing> a thing</thing>

	<thing> a thing</thing>

Afer a few appends, the document is unreadable! I know why it happens
(whitespace is relevant to xml).

How can I do this so that the indents and newlines apply how I want them:

	<thing> a thing</thing>
	<thing> a thing</thing>

Thanks in advance for any advice,

To control your jdom-interest membership:

More information about the jdom-interest mailing list