[jdom-interest] dealing with whitespace when appending elements

Neil Burnett neil at efc.be
Sun Dec 10 11:58:47 PST 2000


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

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:

	<item>

		<thing> a thing</thing>

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

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:

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

 
Thanks in advance for any advice,


Neil



More information about the jdom-interest mailing list