AW: [jdom-interest] DTD-aware document building

Frank Spychalski psycho at
Wed Jan 2 08:34:37 PST 2002


AFAIK there's no such method. 

But how about adding all required children (your 'attributes') in the
correct order after creating the Router element (and setting them to some
default value) and changing these in your setRouterAttribute method.

just my 2 cents

-----Ursprüngliche Nachricht-----
Von: Proneel Guptan [mailto:proneel at]
Gesendet: Mittwoch, 2. Januar 2002 17:08
An: 'jdom-interest at'
Betreff: [jdom-interest] DTD-aware document building

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 

sitewaerts GmbH
Hebelstraße 15
D-76133 Karlsruhe

Tel: +49 (721) 920 918 0
Fax: +49 (721) 920 918 29

More information about the jdom-interest mailing list