title: XML, XPATH adding values
body: <p>i have XML files which contain records with the following structure:</p>
  
  <pre><code>&lt;xml&gt;
     &lt;payment contractType="1"&gt;
       &lt;income type="0"&gt;
         &lt;gr code="1" amount="1506.00"/&gt;
         &lt;gr code="4" amount="35.00"/&gt;
         &lt;gr code="10" amount="288.14"/&gt;
         &lt;de code="3011300" amount="138.72"/&gt;
         &lt;de code="3081100" amount="48"/&gt;
         &lt;de code="3082400" amount="110"/&gt;
       &lt;/income&gt;
       &lt;netAmount1 value="765.00"/&gt;
      &lt;netAmount2 value="765.00"/&gt;
    &lt;/payment&gt; 
   &lt;payment contractType="1"&gt;
       &lt;income type="0"&gt;
         &lt;gr code="1" amount="506.00"/&gt;
         &lt;gr code="4" amount="35.00"/&gt;
         &lt;gr code="10" amount="0"/&gt;
         &lt;de code="3011300" amount="1.28"/&gt;
         &lt;de code="3081100" amount="48"/&gt;
         &lt;de code="3082400" amount="120"/&gt;
       &lt;/income&gt;
       &lt;netAmount1 value="635.00"/&gt;
      &lt;netAmount2 value="635.00"/&gt;
    &lt;/payment&gt; 
  &lt;/xml&gt;
  </code></pre>
  
  <p>each file has many records of type payment and i want the final xml to contain one payment
  record by adding all the amount values for every differrent code value
  the result of the xml above is</p>
  
  <pre><code>&lt;xml&gt;  
    &lt;payment contractType="1"&gt;
       &lt;income type="0"&gt;
         &lt;gr code="1" amount="2512.00"/&gt;
         &lt;gr code="4" amount="70.00"/&gt;
         &lt;gr code="10" amount="288.14"/&gt;
         &lt;de code="3011300" amount="140"/&gt;
         &lt;de code="3081100" amount="96"/&gt;
         &lt;de code="3082400" amount="230"/&gt;
       &lt;/income&gt;
       &lt;netAmount1 value="1400.00"/&gt;
      &lt;netAmount2 value="1400.00"/&gt;
    &lt;/payment&gt; 
  &lt;/xml&gt;
  </code></pre>
  
  <p>I think XPath can be used for this, but I never used it before , could someone show me some Java (or else) code for this?</p>