title: Replacing Elements in a XML document with String in Java
body: <p>I am writing an HTTP server where i will receive an XPATH in an HTTP PUT and the data in the request body. </p>
  
  <p>I will need to replace the result of the XPATH expression with the data in the HTTP request data in an XML document</p>
  
  <p>For example </p>
  
  <p>the XML document is</p>
  
  <pre><code>&lt;presence&gt;
  &lt;tuple id="x8eg92n"&gt;
  &lt;note&gt; i am reading email 3 times a day &lt;/note&gt;
  &lt;/tuple&gt;
  &lt;/presence&gt;
  </code></pre>
  
  <p>The HTTP request is for example something like</p>
  
  <pre><code>  PUT /pidf-manipulation/users/sip:someone@example.com/index/
    ~~/presence/tuple%5b@id='x8eg92n'%5d/note HTTP/1.1
    If-Match: "xyz"
    Host: xcap.example.com
    Content-Type: application/xcap-el+xml
    ...
  
    &lt;note&gt;I'm reading mails on Tuesdays and Fridays&lt;/note&gt;
  </code></pre>
  
  <p>This above should replace the note element in the XML with the one the PUT request. Clients can this way send any XPATH and replace contents of the XML document. </p>
  
  <p>Please help in how this can be done in Java Code. </p>