[jdom-interest] Outputting PIs

Jason Hunter jhunter at collab.net
Thu Nov 30 10:33:51 PST 2000


> But when I take a look at the output I have to see, that the 
> added PI has been appended to the end of my document.

That's because you added the PI after you added the root element.  PIs
may sometimes need to go after the root, so we place them in the order
in which you add them.

There are two ways to do what you want.

First, create a doc with a dummy root element, then call
setMixedContent() passing in a List of PI and root elt, in that order.

Or, create a doc with a *null* root element, add the pi, then add a root
element.

There's a little controversy if the second approach should be allowed,
or even better advertised with a no-arg Document constructor.  The
reason is that having the ability to create a doc without a root elt
breaks a document's well-formedness, and JDOM wants to ensure sure the
doc you create is well-formed.  But not having that ability means you
have to create a dummy root if you want PIs, comments, or anything
before the root.

-jh-



More information about the jdom-interest mailing list