[jdom-interest] getChildren

ted.erickson at usbank.com ted.erickson at usbank.com
Fri Dec 13 06:40:58 PST 2002


Hopefully someone has a better answer to this problem.

The problem:

Grab all children named "watcher" from a list
Append a new child to the list of watchers

The new child appears at the end of the original list instead of at the end
of the watchers list

The solution:

 1- get the list of "tupleID"
 2- remove the children named "tupleID"
 3- add the new "watcher" node
 4- walk through the list of "tupleID" and add each node to the list

Does anyone have a more elegant or intuitive solution?

Ted Erickson

-------------------------
Yes, but i would that the new added watcher will be at the end of the list
of the watcher and not at the end of the element tupleID, because i have a
sequence in the xsd schema associated and so the order must be respect!!!!
How can relize it?

<instance>
             <watcher>a</watcher>
             <watcher>b</watcher>
                         <watcher>c</watcher>
             <tupleID>1</tupleID>
             <tupleID>3</tupleID>

</instance>

MANY THANKS

---------------------------------------------------------------------------------------------------------
Yanked incorrect reply ...
---------------------------------------------------------------------------------------------------------

i have an element accesslist with inside a sequence of instance
element.Each instance consist on 2 different element named watcher and
tupleid.
<instance>
             <watcher>a</watcher>
             <watcher>b</watcher>
             <tupleID>1</tupleID>
             <tupleID>3</tupleID>
</instance>

My desire is to add a new element watcher. So i do:

List watchers = instance.getChildren("watcher");

Element newatcher = new Element("watcher");
newatcher.setText("c");
watchers.add(newatcher);

but i get:

<instance>
             <watcher>a</watcher>
             <watcher>b</watcher>
             <tupleID>1</tupleID>
             <tupleID>3</tupleID>
             <watcher>c</watcher>
</instance>

that it's wrong!!!Where i do the mistake?
BRGS
Antonello






More information about the jdom-interest mailing list