Java XML Attribute Copy copyAttribute(Element source, String srcattr, Element dest, String destattr)

Here you can find the source of copyAttribute(Element source, String srcattr, Element dest, String destattr)

Description

copy a single attribute (if exist)

License

Open Source License

Parameter

Parameter Description
source a parameter
srcattr a parameter
dest a parameter
destattr a parameter

Declaration

public static void copyAttribute(Element source, String srcattr, Element dest, String destattr) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. 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  .  j ava 2  s  . co m*/
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Attr;
import org.w3c.dom.Element;

public class Main {
    /**
     * copy a single attribute (if exist)
     * 
     * @param source
     * @param srcattr
     * @param dest
     * @param destattr
     */
    public static void copyAttribute(Element source, String srcattr, Element dest, String destattr) {
        Attr attr = source.getAttributeNode(srcattr);
        if (attr != null) {
            dest.setAttribute(destattr, attr.getValue());
        }
    }
}

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 sourceElement, String sourceAttrName, Element visualElement, String visualAttrName)
  6. copyAttributeNodes(Element source, Element target)
  7. copyAttributes(Element elementFrom, Element elementTo)
  8. copyAttributes(Element from, Element to)