AW: [jdom-interest] DTD-aware document building
psycho at sitewaerts.de
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
Von: Proneel Guptan [mailto:proneel at dset.com]
Gesendet: Mittwoch, 2. Januar 2002 17:08
An: 'jdom-interest at jdom.org'
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)
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
proneel at dset.com
Tel: +49 (721) 920 918 0
Fax: +49 (721) 920 918 29
More information about the jdom-interest