<br><font size=2 face="sans-serif">If you keep detaching the element it will remove it from the tree</font>
<br>
<br><font size=2 face="sans-serif">I suspect you need code more like</font>
<br>
<br><font size=2 face="Courier New">public void setDef(String string) {<br>
StringTokenizer st = new StringTokenizer(string, "|");<br>
while(st.hasMoreElements()){</font>
<br><font size=2 face="Courier New"> Element listedItem = new Element("listed-item");</font>
<br><font size=2 face="Courier New"> Element number = new Element("number");</font>
<br><font size=2 face="Courier New"> Element type = new Element("type");</font>
<br><font size=2 face="Courier New"> number.setText(st.nextToken());<br>
type.setText(st.nextToken());</font>
<br><font size=2 face="Courier New"> listedItem.addContent(number);</font>
<br><font size=2 face="Courier New"> listedItem.addContent(type);<br>
def.addContent(listedItem);<br>
}<br>
}</font><font size=2 face="sans-serif"><br>
<br>
/Phill<br>
IS Dept, Software Engineer.<br>
phill_perryman@mitel.com<br>
http://www.mitel.com<br>
Tel: +44 1291 436023</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td>
<td><font size=1 face="sans-serif"><b>Flávio Marim <flavio@bs2.com.br></b></font>
<br><font size=1 face="sans-serif">Sent by: jdom-interest-bounces@servlets.com</font>
<p><font size=1 face="sans-serif">08/09/2004 16:53</font>
<br>
<td><font size=1 face="Arial"> </font>
<br><font size=1 face="sans-serif"> To: jdom-interest@jdom.org</font>
<br><font size=1 face="sans-serif"> cc: </font>
<br><font size=1 face="sans-serif"> Subject: [jdom-interest] repeating nodes</font></table>
<br>
<br>
<br><font size=2 face="Courier New">I think I miss something in the docs...<br>
I'm trying to build an XML that has a node wich has multiple children with<br>
the same name as follows:<br>
<br>
<def><br>
<listed-item><br>
<number></number><br>
<type></type><br>
</listed-item><br>
<listed-item><br>
<number></number><br>
<type></type><br>
</listed-item><br>
</def><br>
<br>
I'm getting the data from a string like this:<br>
<br>
|number1|type1|number2|type2|...|numberN|typeN|<br>
<br>
public void setDef(String string) {<br>
StringTokenizer st = new StringTokenizer(string, "|");<br>
while(st.hasMoreElements()){<br>
setNumber(st.nextToken());<br>
setType(st.nextToken());<br>
def.addContent(listedItem.detach());<br>
}<br>
}<br>
<br>
The methods setNumber() and setType() just set text to "number" and "type"<br>
tags.<br>
When the method setDef() is called, the tree is already built.<br>
<br>
The problem: the final built document is<br>
<br>
<def><br>
<listed-item><br>
<number>N</number><br>
<type>N</type><br>
</listed-item><br>
</def><br>
<br>
I mean, only the LAST <listed-item> block is recorded. The <listed-item>'s<br>
are all overwritten. Which one by his next.<br>
<br>
What is the beginner here missing?<br>
<br>
Thanks in advance.<br>
<br>
-- <br>
Flávio Marim<br>
_______________________________________________<br>
To control your jdom-interest membership:<br>
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com<br>
</font>
<br>
<br>