title: How to read, update and delete the existing XML file using node attribute value in Java
body: <p>I am trying to read/update/delete the XML file on the basis of value found.</p>
  
  <p>I have a XML with name <code>123456.xm</code>l with below format.</p>
  
  <pre><code>&lt;ps&gt;
    &lt;p n="359" u="/ae/arabic/plan_book/plan_and_book.aspx"/&gt;
    &lt;p n="277" u="/ae/english/plan_book/plan_and_book.aspx"/&gt;
    &lt;p n="410" u="/ao/english/plan_book/plan_and_book.aspx"/&gt;
  &lt;/ps&gt;
  </code></pre>
  
  <p>Now my new method in java will get Filepath (<code>c://java/Files/12345.xml</code>), n(277 - the value which will be checked in file) and U ("/de/english/plan_book/plan_and_book.aspx").</p>
  
  <p>Logic for my java method will as below, but really don't know how to write.</p>
  
  <p><strong>Adding/Appending Method Logic:</strong></p>
  
  <ol>
  <li>Open the file <code>c://java/Files/12345.xml</code></li>
  <li>Search for all nodes and find the basis of value of n(277). There will be only one record for 277</li>
  <li>If this value exists in the file then no updates are required else add the new node in  xml file, so for example if the value of n would have been (777), as this attribute record does not exists in file then it would have added a new record in file (<code>&lt;p n="777" u="/ao/english/plan_book/plan_and_book.aspx"/&gt;</code>).</li>
  <li>Save the updated XML on same location.</li>
  </ol>
  
  <p><strong>Deleting Method Logic:</strong></p>
  
  <ol>
  <li>Open the file <code>c://java/Files/12345.xml</code></li>
  <li>Search for all nodes and find on the basis of value of n(277). There will be only one record for 277.</li>
  <li>If this value exists in node attribute "n" then it will delete that node from the xml, else no update required.</li>
  <li>Save the updated XML on same location. </li>
  </ol>
  
  <p>Would appreciate if you share some good example or links for above implementaion.</p>
  
  <p>Thanks.</p>