[jdom-interest] repeating nodes

Flávio Marim flavio at bs2.com.br
Wed Sep 8 07:53:49 PDT 2004


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


More information about the jdom-interest mailing list