Java XML Attribute Copy cloneAttributes(Element element, Element targetElement)

Here you can find the source of cloneAttributes(Element element, Element targetElement)

Description

clone Attributes

License

Open Source License

Declaration

private static void cloneAttributes(Element element,
            Element targetElement) 

Method Source Code

//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());
        }
    }
}

Related

  1. cloneAttribute(Node source, Node destination, String attrName)
  2. copyAllAttributes(Element from, Element to)
  3. copyAllAttributes(Element source, Element dest, Set ignore)
  4. copyAttribute(Element source, String srcattr, Element dest, String destattr)
  5. copyAttribute(Element sourceElement, String sourceAttrName, Element visualElement, String visualAttrName)