[jdom-interest] getChildren

Alex Rosen arosen at novell.com
Wed Dec 18 14:16:34 PST 2002


What's wrong with:

Get the list of ALL children
Walk the tree to find the index of the last watcher element
Use List.add() to add the new element right after that one

Alex

>>> <ted.erickson at usbank.com> 12/13/02 09:40AM >>>
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



_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list