[jdom-interest] Reordering elements for DTD compliance

Stephen Colebourne scolebournenews at hotmail.com
Mon Sep 17 03:19:30 PDT 2001

>I've never heard of anything that reformats to a DTD on output.  A DTD
>defines the data, not the output format.  I've never heard of anything
>that attempts to reorder elements based on a DTD.  Seems very

The reason for wanting to format to a DTD is simple - the output from my 
program will be read into another one. That input will be checked against 
the DTD. If the elements are not sorted into order then the DTD validation 
will fail.

There are two solutions to the above problem-
1) Only add the children to an element in an order that you know is 
compatable with the DTD
2) Sort the elements on output

As I don't want changes to the DTD to affect the code, the second is the 
better choice. I've started writing code that will read in the DTD and sort 
the elements into order before calling XMLOutputter.

Is it non-deterministic? Maybe, but it seems like a very real word example 
to me. And it is far more convenient to treat the JDOM tree as a useful data 
structure rather than an absolute version of the XML you want to produce.

Stephen Colebourne

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

More information about the jdom-interest mailing list