/***** Code de MesExemples.com *******/
/**
* @(#)MoveAttributes.java
*
*
* @author
*sakoba(java.mesexemples.com) @version 1.00 2013/7/4
*/
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
public class MoveAttributes {
public static void copyAttributes(Element from, Element to) {
NamedNodeMap attributes = from.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr node = (Attr) attributes.item(i);
to.setAttributeNS(node.getNamespaceURI(), node.getName(),
node.getValue());
}
}
}
Code testé avec le fichier XML Suivant
Sakoba
Adams
Rappel
Ne m'oubliez pas ce week-end!