Java XML NodeList addAll(final Node dst, final NodeList src)

Here you can find the source of addAll(final Node dst, final NodeList src)

Description

Adds all Nodes of the source NodeList to the destination Node

License

Open Source License

Parameter

Parameter Description
dst the destination NodeList
src the source Node

Declaration

public final static void addAll(final Node dst, final NodeList src) 

Method Source Code

//package com.java2s;
/**/*from w w  w  .  j a  v a  2  s .  c  o m*/
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */

import org.w3c.dom.*;

public class Main {
    /**
     * Adds all Nodes of the source NodeList to the destination Node
     * 
     * @param dst the destination NodeList
     * @param src the source Node
     **/
    public final static void addAll(final Node dst, final NodeList src) {
        final int size = size(src);

        for (int i = 0; i < size; i++) {
            dst.appendChild(src.item(i));
        }
    }

    /**
     * Retrieves the number of Nodes in the NodeList
     * 
     * @param nodeList the NodeList
     * @return the number of Nodes
     **/
    public final static int size(final NodeList nodeList) {
        return nodeList == null ? 0 : nodeList.getLength();
    }

    /**
     * Retrieves the number of Nodes in the NamedNodeMap
     * 
     * @param nodeMap the NamedNodeMap
     * @return the number of Nodes
     **/
    public final static int size(final NamedNodeMap nodeMap) {
        return nodeMap == null ? 0 : nodeMap.getLength();
    }

    /**
     * Retrieves the number of Nodes in the tree rooted at the given Node
     * 
     * @param node the root Node
     * @return the number of Nodes
     **/
    public final static int size(final Node node) {
        if (node == null) {
            return 0;
        }

        final NodeList children = node.getChildNodes();
        int size = 1;
        for (int i = 0, n = size(children); i < n; i++) {
            size += size(children.item(i));
        }

        return size;
    }

    /**
     * Appends a child to the given xml Node
     * 
     * @param xml the parent Node
     * @param child the child Node to append to parent
     **/
    public final static void appendChild(final Node xml, final Node child) {
        if ((xml == null) || (child == null)) {
            return;
        }
        xml.appendChild(child);
    }
}

Related

  1. asList(final NodeList scripts)
  2. asList(NodeList nodeList)
  3. canonizeNodeList(NodeList nodelist)
  4. combine(final NodeList... nls)