Java XML Attribute Copy copyAttribute(Element sourceElement, String sourceAttrName, Element visualElement, String visualAttrName)

Here you can find the source of copyAttribute(Element sourceElement, String sourceAttrName, Element visualElement, String visualAttrName)

Description

Copies all attributes from source node to visual node.

License

Open Source License

Parameter

Parameter Description
sourceElement the source element
sourceAttrName the name of source attribute
visualElement the visual element
visualAttrName the resulting name of visual attribute

Declaration

public static void copyAttribute(Element sourceElement, String sourceAttrName, Element visualElement,
        String visualAttrName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007-2014 Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is 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
 *
 * Contributor://from w  ww  .jav a2s  .c  o  m
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import org.w3c.dom.Element;

public class Main {
    /**
     * Copies all attributes from source node to visual node.
     * 
     * @param sourceElement the source element
     * @param sourceAttrName the name of source attribute 
     * @param visualElement the visual element
     * @param visualAttrName the resulting name of visual attribute 
     */
    public static void copyAttribute(Element sourceElement, String sourceAttrName, Element visualElement,
            String visualAttrName) {
        if (sourceElement.hasAttribute(sourceAttrName)) {
            String attrValue = sourceElement.getAttribute(sourceAttrName);
            visualElement.setAttribute(visualAttrName, attrValue);
        }
    }
}

Related

  1. cloneAttribute(Node source, Node destination, String attrName)
  2. cloneAttributes(Element element, Element targetElement)
  3. copyAllAttributes(Element from, Element to)
  4. copyAllAttributes(Element source, Element dest, Set ignore)
  5. copyAttribute(Element source, String srcattr, Element dest, String destattr)
  6. copyAttributeNodes(Element source, Element target)
  7. copyAttributes(Element elementFrom, Element elementTo)
  8. copyAttributes(Element from, Element to)
  9. copyAttributes(Element from, Element to, NodeFilter filter)