Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import org.w3c.dom.Node;

public class Main {
    /**
     * Removes all children nodes with the specific name of the given node
     * @param node
     */
    public static void removeChildren(Node node, String name) {
        if (node == null)
            return;

        for (Node item : getChildrenByTagName(node, name)) {
            node.removeChild(item);
        }
    }

    /**
     * Returns a list of children with the specified name
     * @param name
     * @return
     */
    public static ArrayList<Node> getChildrenByTagName(Node node, String name) {
        ArrayList<Node> list = new ArrayList<Node>();
        if (node == null)
            return list;

        for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            if (child.getNodeName().equals(name))
                list.add(child);
        }

        return list;
    }
}