title: Putting XML elements in JTable
body: <p>I am trying to parse an XML file with sax parser in Java and then fill a <code>JTable</code> with the XML elements. The parsing is well done, the <code>JTable</code> is created, but the problem is that all the elements are placed in the same row and the same row is repeated.</p>
  <p>Here is my code :</p>
  <pre><code>package read;
  
  //import java.util.ArrayList;
  import java.awt.BorderLayout;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Vector;
  import javax.swing.JFrame;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  public class Read {
  
      public static Vector&lt;Vector&gt; rowData = new Vector&lt;Vector&gt;();
      public static Vector&lt;String&gt; rowOne = new Vector&lt;String&gt;();
  
      public static void main(String argv[]) {
          try {
              SAXParserFactory factory = SAXParserFactory.newInstance();
              SAXParser saxParser = factory.newSAXParser();
              DefaultHandler handler;
              handler = new DefaultHandler() {
                  // private List&lt;Personne&gt; satff;
                  boolean bstaff = false;
                  boolean bfname = false;
                  boolean blname = false;
                  boolean bnname = false;
                  boolean bsalary = false;
                  private int i;
  
                  public void startElement(String uri, String localName, String
                      qName, Attributes attributes) throws SAXException {
                      System.out.println(&quot;Start Element :&quot; + qName);
                      if (qName.equalsIgnoreCase(&quot;staff&quot;)) {
                          bstaff = true;
                      }
                      if (qName.equalsIgnoreCase(&quot;FIRSTNAME&quot;)) {
                          bfname = true;
                      }
                      if (qName.equalsIgnoreCase(&quot;LASTNAME&quot;)) {
                          blname = true;
                      }
                      if (qName.equalsIgnoreCase(&quot;NICKNAME&quot;)) {
                          bnname = true;
                      }
                      if (qName.equalsIgnoreCase(&quot;SALARY&quot;)) {
                          bsalary = true;
                      }
                  }
  
                  public void endElement(String uri, String localName,
                      String qName) throws SAXException {
                      System.out.println(&quot;End Element :&quot; + qName);
                      if (&quot;staff&quot;.equals(qName)) {
                          rowData.addElement(rowOne);
                      };
                  }
  
                  @Override
                  public void characters(char ch[], int start, int length) {
                      if (bfname) {
                          String s = new String(ch, start, length);
                          rowOne.addElement(s);
                          System.out.println(&quot;First Name : &quot; + new String(ch, start, length));
                          bfname = false;
                      }
                      if (blname) {
                          rowOne.addElement(new String(ch, start, length));
                          System.out.println(&quot;Last Name : &quot; + new String(ch, start, length));
                          blname = false;
                      }
                      if (bnname) {
                          rowOne.addElement(new String(ch, start, length));
                          System.out.println(&quot;Nick Name : &quot; + new String(ch, start, length));
                          bnname = false;
                      }
                      if (bsalary) {
                          rowOne.addElement(new String(ch, start, length));
                          System.out.println(&quot;Salary : &quot; + new String(ch, start, length));
                          //rowData.addElement(rowOne);
                          bsalary = false;
                      }
                      System.out.println(&quot;longueur&quot; + rowOne.size());
                  }
              };
              saxParser.parse(&quot;file.xml&quot;, handler);
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Vector&lt;String&gt; columnNames = new Vector&lt;String&gt;();
              columnNames.addElement(&quot;firstname&quot;);
              columnNames.addElement(&quot;lastname&quot;);
              columnNames.addElement(&quot;nickname&quot;);
              columnNames.addElement(&quot;salary&quot;);
              columnNames.addElement(&quot; &quot;);
              columnNames.addElement(&quot; &quot;);
              columnNames.addElement(&quot; &quot;);
              columnNames.addElement(&quot; &quot;);
              JTable table = new JTable(rowData, columnNames);
              JScrollPane scrollPane = new JScrollPane(table);
              frame.add(scrollPane, BorderLayout.CENTER);
              frame.setSize(300, 150);
              frame.setVisible(true);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>My original XML file is the folowing:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;company&gt;
  &lt;staff &gt;
  &lt;firstname&gt;yong&lt;/firstname&gt;
  &lt;lastname&gt;mook kim&lt;/lastname&gt;
  &lt;nickname&gt;mkyong&lt;/nickname&gt;
  &lt;salary&gt;100000&lt;/salary&gt;
  &lt;/staff&gt;
  &lt;staff &gt;
  &lt;firstname&gt;low&lt;/firstname&gt;
  &lt;lastname&gt;yin fong&lt;/lastname&gt;
  &lt;nickname&gt;fong fong&lt;/nickname&gt;
  &lt;salary&gt;200000&lt;/salary&gt;
  &lt;/staff&gt;
  &lt;/company&gt;
  </code></pre>