title: How can I parse XML using Java?
body: <pre><code>&lt;?xml version="1.0" ?&gt; 
  &lt;input&gt;
      &lt;sys&gt;
        &lt;protocol&gt;TL1&lt;/protocol&gt; 
        &lt;ipAddress&gt;10.05.2.3&lt;/ipAddress&gt;
        &lt;port&gt;2001&lt;/port&gt;
        &lt;prompt&gt;agent&lt;/prompt&gt;       
         &lt;TL1Command&gt;
             &lt;type&gt;get&lt;/type&gt;
             &lt;command_code&gt;...........&lt;/command_code&gt;
             &lt;staging_block&gt;      
                  &lt;tid&gt;...........&lt;/tid&gt;
                  &lt;aid&gt;...........&lt;/aid&gt;
                  &lt;ctag&gt;..........&lt;/ctag&gt;
                  &lt;gen_block&gt;.....&lt;/gen_block&gt;
             &lt;/staging_block&gt;
             &lt;payload_block&gt;
                  &lt;data_block&gt;.......&lt;/data_block&gt;
             &lt;/payload_block&gt;
      &lt;/TL1Command&gt;
      &lt;/sys&gt;
      &lt;sys&gt;
        &lt;protocol&gt;TL1&lt;/protocol&gt; 
        &lt;ipAddress&gt;10.5.2.98&lt;/ipAddress&gt;
        &lt;port&gt;2001&lt;/port&gt;
        &lt;prompt&gt;agent&lt;/prompt&gt;       
         &lt;TL1Command&gt;
             &lt;type&gt;get&lt;/type&gt;
             &lt;command_code&gt;...........&lt;/command_code&gt;
             &lt;staging_block&gt;      
                  &lt;tid&gt;...........&lt;/tid&gt;
                  &lt;aid&gt;...........&lt;/aid&gt;
                  &lt;ctag&gt;..........&lt;/ctag&gt;
                  &lt;gen_block&gt;.....&lt;/gen_block&gt;
             &lt;/staging_block&gt;
             &lt;payload_block&gt;
                  &lt;data_block&gt;.......&lt;/data_block&gt;
                  &lt;data_block&gt;.......&lt;/data_block&gt;
                  &lt;data_block&gt;.......&lt;/data_block&gt;
             &lt;/payload_block&gt;
      &lt;/TL1Command&gt;
      &lt;/sys&gt;
  &lt;/input&gt;
  </code></pre>
  
  <p>I want to know how to parse this XML using Java. Such that I can use that data as it is in the same given way for my program. I know of how to parse it but the problem is for each command there might be different number of data blocks. So after parsing I need to use respective datablocks for respective commands. I mean for first command while retriving I should get only one data block value and for 2nd command 3 data blocks and so on. Please let me know any sample code for solving this issue.</p>