[jdom-interest] ordering elements within an XML document

Bradley S. Huffman hip at cs.okstate.edu
Mon Oct 27 15:54:58 PST 2003

Which version of JDOM?  If your using the current CVS you can just do

    Element root = document.getRootElement();
    root.addContent(0, newChild);

With B9 and before you'll first have to get root's content as a List, as in

    Element root = document.getRootElement();
    List content = root.getContent();
    content.add(0, newChild);


"William Krick" writes:

> 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
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost
> .com

More information about the jdom-interest mailing list