Here you can find the source of cloneAttributes(Element element, Element targetElement)
private static void cloneAttributes(Element element, Element targetElement)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2014 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w.ja v a 2 s . c om * SAP AG - initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { private static void cloneAttributes(Element element, Element targetElement) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); ++i) { Node attribute = attributes.item(i); targetElement.setAttribute(attribute.getNodeName(), attribute.getTextContent()); } } }