[jdom-interest] iterative addChild
Vamshi Reddy
Vamshi.Reddy at whn.com
Fri Oct 6 22:03:45 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);
> }
? You might be able to add with the iterator() but the changes might not be
reflected in the document.
? You might get a IllegalAddException if you go around this because the
parent already exists.
If this is what you want: <events>
<event />
<event />
<new element fillevent here?>
</events>
Try eventslist.add(fillevent). This should add the new element <events> at
the end of that list (eventslist). If not, you have to make a new parent and
add the content to a new parent element.
- Vamshi
More information about the jdom-interest
mailing list