Here you can find the source of copyAllAttributes(Element from, Element to)
public static void copyAllAttributes(Element from, Element to)
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Attr; import org.w3c.dom.Element; public class Main { public static void copyAllAttributes(Element from, Element to) { NamedNodeMap attrs = from.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i < attrCount; ++i) { Attr attr = (Attr) attrs.item(i); to.setAttributeNS(attr.getNamespaceURI(), /*QName*/ attr.getName(), attr.getValue()); }/*from w w w. j a va 2 s . co m*/ } }