Source Code : Java DOM edit: Replacing an Existing Node with a New One
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Java DOM edit: Replacing an Existing Node with a New One
public void replacePerson(Document doc, String name,String phone,String email) {
Element newPersonNode = doc.createElement("person");
Element nameNode = doc.createElement("name");
newPersonNode.appendChild(nameNode);
Text nametextNode = doc.createTextNode(name);
nameNode.appendChild(nametextNode);
Element phoneNode = doc.createElement("phone");
newPersonNode.appendChild(phoneNode);
Text phonetextNode = doc.createTextNode(phone);
phoneNode.appendChild(phonetextNode);
Element emailNode = doc.createElement("email");
newPersonNode.appendChild(emailNode);
Text emailtextNode = doc.createTextNode(email);
emailNode.appendChild(emailtextNode);
Element root = doc.getDocumentElement();
Element oldPersonNode = (Element)root.getFirstChild();
root.replaceChild(newPersonNode,oldPersonNode);
}
Thank with us