title: Read data from XML file (in Java) using Reflection
body: <p>Given a simple XML file , like : </p>
  
  <pre><code>&lt;Game&gt;
      &lt;Round&gt;
          &lt;roundNumber&gt;1&lt;/roundNumber&gt;
          &lt;Door&gt;
              &lt;doorName&gt;abd11&lt;/doorName&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;0&lt;/xVal1&gt;
                  &lt;xVal2&gt;25&lt;/xVal2&gt;
                  &lt;pVal&gt;0.31&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;25&lt;/xVal1&gt;
                  &lt;xVal2&gt;50&lt;/xVal2&gt;
                  &lt;pVal&gt;0.04&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;50&lt;/xVal1&gt;
                  &lt;xVal2&gt;75&lt;/xVal2&gt;
                  &lt;pVal&gt;0.19&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;75&lt;/xVal1&gt;
                  &lt;xVal2&gt;100&lt;/xVal2&gt;
                  &lt;pVal&gt;0.46&lt;/pVal&gt;
              &lt;/Value&gt;
          &lt;/Door&gt;
          &lt;Door&gt;
              &lt;doorName&gt;vvv1133&lt;/doorName&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;60&lt;/xVal1&gt;
                  &lt;xVal2&gt;62&lt;/xVal2&gt;
                  &lt;pVal&gt;1.0&lt;/pVal&gt;
              &lt;/Value&gt;
          &lt;/Door&gt;
      &lt;/Round&gt;
      &lt;Round&gt;
          &lt;roundNumber&gt;2&lt;/roundNumber&gt;
          &lt;Door&gt;
              &lt;doorName&gt;eee&lt;/doorName&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;0&lt;/xVal1&gt;
                  &lt;xVal2&gt;-25&lt;/xVal2&gt;
                  &lt;pVal&gt;0.31&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;-25&lt;/xVal1&gt;
                  &lt;xVal2&gt;-50&lt;/xVal2&gt;
                  &lt;pVal&gt;0.04&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;-50&lt;/xVal1&gt;
                  &lt;xVal2&gt;-75&lt;/xVal2&gt;
                  &lt;pVal&gt;0.19&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;-75&lt;/xVal1&gt;
                  &lt;xVal2&gt;-100&lt;/xVal2&gt;
                  &lt;pVal&gt;0.46&lt;/pVal&gt;
              &lt;/Value&gt;
          &lt;/Door&gt;
          &lt;Door&gt;
              &lt;doorName&gt;cc&lt;/doorName&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;-60&lt;/xVal1&gt;
                  &lt;xVal2&gt;-62&lt;/xVal2&gt;
                  &lt;pVal&gt;0.3&lt;/pVal&gt;
              &lt;/Value&gt;
              &lt;Value&gt;
                  &lt;xVal1&gt;-70&lt;/xVal1&gt;
                  &lt;xVal2&gt;-78&lt;/xVal2&gt;
                  &lt;pVal&gt;0.7&lt;/pVal&gt;
              &lt;/Value&gt;
          &lt;/Door&gt;
      &lt;/Round&gt;
  &lt;/Game&gt;
  </code></pre>
  
  <p>I want to read data from that file . </p>
  
  <p>I can do it in the old fashioned way of reading the tags , and create the objects accordingly , </p>
  
  <p>but I want to do it using Reflection mechanism . </p>
  
  <p>Can someone please explain or direct me to a tutorial that can explain how to do that ? </p>
  
  <p>Thanks </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I did the following : </p>
  
  <pre><code>import java.io.File;
  import org.w3c.dom.Document;
  import org.w3c.dom.*;
  
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.DocumentBuilder;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXParseException; 
  
  public class ReadAndPrintXMLFile {
  
  
      public static void main (String argv []){
      try {
  
              DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
              DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
              Document doc = docBuilder.parse (new File("input.xml"));
  
  
              // ROOT 
  
              // normalize text representation
              doc.getDocumentElement ().normalize ();
              System.out.println ("Root element of the doc is " + 
                   doc.getDocumentElement().getNodeName());
  
  
              // Number of nodes/rounds 
  
  
              NodeList listOfItems = doc.getElementsByTagName("Round");
              int totalElements = listOfItems.getLength();
              System.out.println("Total number of nodes : " + totalElements );
  ...
  ...
  }
  </code></pre>
  
  <p>This is a partial code , I ran the code and tested it , and at the moment , using SAX , I 
  can read from the XML file above .</p>
  
  <p>Now , what I want to do is to manipulate the data using Reflection . From my understanding Reflection works only with EXISTING objects . Hence , is it enough to store the data (I.E. the rounds)  in the variable <code>listOfItems</code> and now use Reflection on that ? </p>
  
  <p>thanks again !</p>