[jdom-interest] ordering elements within an XML document

William Krick wkrick at eio-online.com
Mon Oct 27 14:46:26 PST 2003


Hello all,

I have what I hope is a simple problem with a simple solution.

My application works with hierarchical data that is stored internally within
a database.  My application gives the user the ability to export this data
in XML format.  I would like to add a tag to the created XML document that
holds the creation date/time expressed as a string.

Unfortunately, if I take the existing document object (before it is output),
get the root element, and add a new tag, it ends up at the end of the
document.   For human readability reasons, I'd like the date/time tag to be
at the top of the document.

After looking at the problem a bit, it seems that the only option I have is
to pull the Document object apart (getting a list of child elements), create
a new Document, add my date/time tag, and then append all the child elements
to it.  An ugly proposal at best.

Is there some magic method that I'm missing that will solve this problem for
me?

Should I be storing the date/time as an attribute of the root element
instead?

...
Krick





More information about the jdom-interest mailing list