[jdom-interest] How would I generate this XML

Jason Hunter jhunter at collab.net
Fri Jul 14 00:23:29 PDT 2000

> his samples. Whilst playing around with it, I found it difficult to
> generate the following XML
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- Yusuf's first comment -->
>   Hello JDOM!

Yes, it's tricky to create this document.  You have to be sneaky and
pass in a null root element to the constructor, then add the comment,
then set the real root element.  One method that was unintentionally
left out of the API is a Document.setMixedContent() method.  That would
make this possible without being sneaky.  Apparently this method doesn't
get much use since no one mentioned anything and I only realized it was
missing two days ago.  :-)  It's something to fix before beta5.

BTW, on setMixedContent() I'm suspect we should verify there's only
*one* Element present in the specified list to keep a document from
having two root elements, and we should throw an IllegalAddException or
something similar if necessary.  Anyone see a reason not to?  And no,
it's not enough to return null in this case!  :-)


More information about the jdom-interest mailing list