[jdom-interest] iterative addChild

Patrick Dowler Patrick.Dowler at nrc.ca
Fri Oct 6 11:18:40 PDT 2000


On Fri, 06 Oct 2000, Paul Madsen wrote:
> I'm trying to iterate through an elements children, adding children as I
> go between each existing child and the following one.
> 
> When I try:
> 
>       Element events = root.getChild("events");
>       List eventslist = events.getChildren("event");
> 
>      Iterator iterator = eventslist.iterator();
>      while (iterator.hasNext()) {
>           Object o = iterator.next();
> 
>           Element e_event = (Element) o;
> 
>          Element fillevent = new Element("fillevent");
>          events.addChild(fillevent);
>   }

Use ListIterator and iterator.add(fillEvent) rather than events.add(fillEvent).
When you add to events, it just gets appended (the iterator position is
irrelevant). 

However, I think there was a problem with ListIterator properly mutating the
PartialList... was that fixed yet?

--

Patrick Dowler
Canadian Astronomy Data Centre




More information about the jdom-interest mailing list