Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] repeating nodes

Flávio Marim

2004-09-08


I think I miss something in the docs...
I'm trying to build an XML that has a node wich has multiple children with
the same name as follows:

<def>
 <listed-item>
   <number></number>
   <type></type>
 </listed-item>
 <listed-item>
   <number></number>
   <type></type>
 </listed-item>
</def>

I'm getting the data from a string like this:

|number1|type1|number2|type2|...|numberN|typeN|

public void setDef(String string) {
 StringTokenizer st = new StringTokenizer(string, "|");
 while(st.hasMoreElements()){
   setNumber(st.nextToken());
   setType(st.nextToken());
   def.addContent(listedItem.detach());
 }
}

The methods setNumber() and setType() just set text to "number" and "type"
tags.
When the method setDef() is called, the tree is already built.

The problem: the final built document is

<def>
 <listed-item>
   <number>N</number>
   <type>N</type>
 </listed-item>
</def>

I mean, only the LAST <listed-item> block is recorded. The <listed-item>'s
are all overwritten. Which one by his next.

What is the beginner here missing?

Thanks in advance.

--
Fl�vio Marim
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.