[jdom-interest] Feature request

Eric VERGNAUD eric.vergnaud at wanadoo.fr
Fri Jul 4 15:04:39 PDT 2003


Hi all,

Since we're talking about simplicity, I sometimes find that it requires some
heavy writing when you're doing very light things.

In the documents I create, there is very often only one single child.
Typically, the output looks like that:

<root>
    <child_level_1>
        <child_level_2>
            <child_level_3>
                <child_level_4>
                Data
                </child_level_4>
            </child_level_3>
        </child_level_2>
    </child_level_1>
    <child_level_1>
        <child_level_2>
            <child_level_3>
                <child_level_4>
                Data
                </child_level_4>
            </child_level_3>
        </child_level_2>
    </child_level_1>
</root>

I haven't found a way to simply add one single child to an element, so my
code looks like the following:

list1 = new ArrayList();

// create first child
child1 = new Element("child_level_1");
list1.add(child1);

list2 = new ArrayList();
child2 = new Element(("child_level_2");
list2.add(child2);
child1.setChildren(list2);

list3 = new ArrayList();
child3 = new Element(("child_level_3");
list3.add(child3);
child2.setChildren(list3);

list4 = new ArrayList();
child4 = new Element(("child_level_4");
list4.add(child4);
child3.setChildren(list4);

// create second child
child1 = new Element("child_level_1");
list1.add(child1);

list2 = new ArrayList();
child2 = new Element(("child_level_2");
list2.add(child2);
child1.setChildren(list2);

list3 = new ArrayList();
child3 = new Element(("child_level_3");
list3.add(child3);
child2.setChildren(list3);

list4 = new ArrayList();
child4 = new Element(("child_level_4");
list4.add(child4);
child3.setChildren(list4);

root.setChildren(list1);

A bit heavy, don't you think ? I would very much appreciate to be able to
write simply:

list1 = new ArrayList();

// create first child
child1 = new Element("child_level_1");
list1.add(child1);

child2 = new Element(("child_level_2");
child1.setChild(child2 );

child3 = new Element(("child_level_3");
child2. setChild(child3 );

child4 = new Element(("child_level_4");
child3. setChild(child4 );

// create second child
child1 = new Element("child_level_1");
list1.add(child1);

child2 = new Element(("child_level_2");
child1. setChild(child2 );

child3 = new Element(("child_level_3");
child2. setChild(child3 );

child4 = new Element(("child_level_4");
child3. setChild(child4 );

root.setChildren(list1);

What do you think ?





More information about the jdom-interest mailing list