Java XML Attribute Copy copyAttributes(Element fromEl, Element toEl)

Here you can find the source of copyAttributes(Element fromEl, Element toEl)

Description

copy all attributes form one element to another

License

Open Source License

Parameter

Parameter Description
fromEl a parameter
toEl a parameter

Declaration

public static void copyAttributes(Element fromEl, Element toEl) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

public class Main {
    /**//  w  w w. ja  va  2  s. c  o m
     * copy all attributes form one element to another
     * @param fromEl
     * @param toEl
     */
    public static void copyAttributes(Element fromEl, Element toEl) {
        for (int a = 0; a < fromEl.getAttributes().getLength(); a++) {
            Attr at = (Attr) fromEl.getAttributes().item(a);
            toEl.setAttribute(at.getName(), at.getValue());
        }
    }
}

Related

  1. copyAttribute(Element sourceElement, String sourceAttrName, Element visualElement, String visualAttrName)
  2. copyAttributeNodes(Element source, Element target)
  3. copyAttributes(Element elementFrom, Element elementTo)
  4. copyAttributes(Element from, Element to)
  5. copyAttributes(Element from, Element to, NodeFilter filter)
  6. copyAttributes(final Element destElement, final Element srcElement)
  7. copyAttributes(Node from, Node to)
  8. copyAttributes(Node sourceNode, Element visualElement)
  9. copyAttributes(SOAPElement target, Element source)