title: how to replace a dom node with new node?
body: <p>I want to replace a existing Dom node with a new node I have created.I am implementing this as </p>
  
  <pre><code>String messageBody=" &lt;imgGroup&gt;&lt;img src="src" width="width" height="height" alt="alt" type="type" orient="orient"/&gt;&lt;/imgGroup&gt;"
  File file=new File("doc.xml");
                  DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
                  DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
                  doc = docBuilder.parse(file);
                 Element node =  DocumentBuilderFactory
                  .newInstance()
                  .newDocumentBuilder()
                  .parse(new ByteArrayInputStream(messageBody.getBytes()))
                  .getDocumentElement();
                 System.out.println(node.getClass());
                 doc.getDocumentElement().replaceChild((Node)node, doc.getDocumentElement().getFirstChild());
                  }catch(Exception e){
                      e.printStackTrace();
                  }
  </code></pre>
  
  <p>I am getting an run time  error 
  <code>WRONG_DOCUMENT_ERR:</code> A node is used in a different document than the one that created it.</p>
  
  <p>Can any one suggest how to do it in different way?</p>