[jdom-interest] XMLOutputter Questions

Jason Hunter jhunter at collab.net
Wed Apr 11 07:46:03 PDT 2001


Fred Clewis wrote:
> 
> I have an XML String that I need to change a couple of attribute values in.
> So I build a JDOM Document and do that with ease. The problem is getting my
> String back resembling the input String.  I am using XMLOutputter as I
> assume  Document's getSerializedForm is not implemented.   I have two
> difficulties:
>      1. The input XML String may have it's DocType declaration commented
> out.  XMLOutputter will add a new DocType statement in this case.  Is there
> anyway to prevent this.

Are you using DOMBuilder or SAXBuilder?  JDOM never adds a DocType
unless you truly have one, but DOM sometimes does so if you build from
DOM you might get one.  SAXBuilder is the right choice for building from
files, as the javadocs say.

>      2.  Newline characters in the prolog seem to be ignored, making
> several prolog lines and the root tag one line.  setNewlines fixes the
> prolog but inserts extra unwanted newlines everywhere else.

Whitespace in the prolog isn't reported by SAX (due to the fact it's
semantically unimportant), so JDOM has to guess.  The latest code in CVS
is a bit better at guessing I believe than beta6.  Might want to try
it.  There was a patch sent in recently for another tweak to the
guessing logic to make it better still.

-jh-



More information about the jdom-interest mailing list