title: How to update XML using XPath and Java
body: <p>I have an XML document, and an XPath expression for that doc. I have to update the doc by using XPath at runtime.</p>
  
  <p>How can I do this using Java?</p>
  
  <p>The below is my xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;PersonList&gt;
      &lt;Person&gt;
          &lt;Name&gt;Sonu Kapoor&lt;/Name&gt;
          &lt;Age&gt;24&lt;/Age&gt;
          &lt;Gender&gt;M&lt;/Gender&gt;
          &lt;PostalCode&gt;54879&lt;/PostalCode&gt;
      &lt;/Person&gt;
      &lt;Person&gt;
          &lt;Name&gt;Jasmin&lt;/Name&gt;
          &lt;Age&gt;28&lt;/Age&gt;
          &lt;Gender&gt;F&lt;/Gender&gt;
          &lt;PostalCode&gt;78745&lt;/PostalCode&gt;
      &lt;/Person&gt;
      &lt;Person&gt;
          &lt;Name&gt;Josef&lt;/Name&gt;
          &lt;Age&gt;232&lt;/Age&gt;
          &lt;Gender&gt;F&lt;/Gender&gt;
          &lt;PostalCode&gt;53454&lt;/PostalCode&gt;
      &lt;/Person&gt;
  &lt;/PersonList&gt;
  </code></pre>
  
  <p>I have to change the values of name and age under <code>//PersonList/Person[2]/Name</code>.</p>