Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.*;

import org.w3c.dom.*;

public class Main {
    public static List<Node> getChildrenByTagName(Node node, String element) {
        List<Node> result = new ArrayList<Node>();
        NodeList childNodes = node.getChildNodes();
        for (int j = 0; j < childNodes.getLength(); j++) {
            Node childNode = childNodes.item(j);
            if ("*".equals(element) || element == null || childNode.getNodeName().equals(element)) {
                result.add(childNode);
            }
        }
        return result;
    }

    public static List<Node> getChildNodes(Node node, String... elements) {
        List<Node> result = new ArrayList<Node>();
        NodeList childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            for (String element : elements) {
                if (element.equals(childNode.getNodeName())) {
                    result.add(childNode);
                }
            }
        }
        return result;
    }
}