title: Using a for loop to add nodes using DOM to an XML
body: <p>Okay so I have a program that asks for a number of people. Then, for each person it asks the collar of: shirt and paints. I want java to put all this information into an XML using DOM.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>import java.io.*;
  import org.w3c.dom.*;
  import org.xml.sax.*;
  import javax.xml.parsers.*;
  import javax.xml.transform.*;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  
  public class calcWithMem {
      public static void main(String[] args) throws Exception{
          System.out.println("Program launched");
          BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
          DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
          Document doc = builder.newDocument();
          Element root = doc.createElement("People");
          doc.appendChild(root);
          System.out.print("Number of people: ");
          String in = bf.readLine();
          int ppl = Integer.parseInt(in);
          String[] pants = new String[ppl];
          String[] shirt = new String[ppl];
          for (int i=0;i&lt;ppl;i++) {
                      //So what I want is for here to add a new node to the root called "Person 1, Person2, ... etc.)
              System.out.print("Colour of PANTS for person #" + String.valueOf(i+1) + ": ");
              in = bf.readLine();
              pants[i] = in;
                      //And then have a node added to the person with pants
              System.out.print("Colour of SHIRT for person #" + String.valueOf(i+1) + ": ");
              in = bf.readLine();
              shirt[i] = in;
                      //and one last node added to the person with shirt, after this it repeats for each person
              System.out.println();
          }
          for (int i=0;i&lt;ppl;i++) {
              System.out.println("Person #" + String.valueOf(i+1) + ":");
              System.out.println("    Pants: " + pants[i]);
              System.out.println("    Shirt: " + shirt[i]);
          }
      }
  }
  </code></pre>