[jdom-interest] DTD-aware document building

Proneel Guptan proneel at dset.com
Wed Jan 2 08:07:54 PST 2002


I couldnt find anything in the archives which answers the following question
I have, hence the posting.

I have a DTD with a type defined as follows:
<!ELEMENT Router (id , type , routerId , routerName  .... )

When I want to construct a brand new document of type Router, I do the
doc = new Document(new Element("Router"));

After which, I get values from the client for id, type, routerId etc. I may
not get it in the order defined in the DTD.
For eg: my generic method setRouterAttribute(String name, String value)
would simply:
Element child = new Element(name);
rootElement.addContent(child); // where rootElement is the root of the
"Router" document I created

Depending on the order the client calls the setRouterAttribute() to set the
id, type etc, that is the order in which
the document would be created and if this doesnt match the DTD, the document
would be invalid. I do not want to
hard-code into my client the order in which the calls should be made, I'd
much rather want the document builder to
do that automatically, so that if I change the order of fields in the DTD, I
dont need to change my client program also.

Is there any JDOM method, which when I add a child to a node, adds it in the
correct position as defined by the DTD?

Before JDOM, I used a home grown tool which did that and which I found very
convenient. However, from reading up on
various Java&XML tools, I get the impression I belong to (probably) a
minority among XML users who think that DTD
or schema aware document manipulation (as shown by the above example) is

Any comments/clarifications?

proneel at dset.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020102/0be66282/attachment.htm

More information about the jdom-interest mailing list