Java DOM edit: Copying Attributes
public void dupAttributes(Document doc) {
Element root = doc.getDocumentElement();
Element personOne = (Element)root.getFirstChild();
Element personTwo = (Element)personOne.getNextSibling();
Element personThree = (Element)personTwo.getNextSibling();
Attr deptAttr = personOne.getAttributeNode("dept");
personOne.removeAttributeNode(deptAttr);
String deptString = deptAttr.getValue();
personTwo.setAttribute("dept",deptString);
personThree.setAttribute("dept",deptString);
String mailString = personOne.getAttribute("mail");
personTwo.setAttribute("mail",mailString);
String titleString = personOne.getAttribute("title");
personOne.removeAttribute("title");
personThree.setAttribute("title",titleString);
}
Related examples in the same category