[jdom-interest] getChildren(String) implementation
Reinhard Nägele
reinhard.naegele at mgm-edv.de
Tue Jul 15 01:32:35 PDT 2003
The Element's getChildren(String) method returns a list that is a view
on the whole content list. As a result, adding elements to this list
doesn't take the view into account. Unfortunately...
Look at the following example XML:
<myRoot>
<myElement1 />
<myElement1 />
<myElement1 />
<myElement2 />
<myElement2 />
<myElement2 />
</myRoot>
I was doing something like this:
List list = myRoot.getChildren("myElement1");
list.add(new Element("myElement1"));
I expected to get the following:
<myRoot>
<myElement1 />
<myElement1 />
<myElement1 />
<myElement1 />
<myElement2 />
<myElement2 />
<myElement2 />
</myRoot>
But of course, the result was this:
<myRoot>
<myElement1 />
<myElement1 />
<myElement1 />
<myElement2 />
<myElement2 />
<myElement2 />
<myElement1 />
</myRoot>
From looking at the JDOM source, I understand why I get this result,
but I think this could have been implemented differently. Wouldn't it be
desirable that the view on the whole list knew where to insert new
elements, i. e. any insert on the view were relative to the view?
Any thoughts appreciated.
Reinhard
More information about the jdom-interest
mailing list