Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {

    public static List<Node> getChildNodeList(Node parentNode, String nodeName) {
        List<Node> childNodeList = new ArrayList<>();
        NodeList nodeList = parentNode.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node childNode = nodeList.item(i);
            if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                if (((Element) childNode).getNodeName().equals(nodeName)) {
                    childNodeList.add(childNode);
                }
            }
        }
        return childNodeList;
    }
}