Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static List<Node> getValidChildNodes(Node node) {
        List<Node> nl = new ArrayList<>();
        NodeList nodeList = node.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            if (isValidNode(nodeList.item(i)))
                nl.add(nodeList.item(i));
        }
        return nl;
    }

    public static boolean isValidNode(Node node) {
        return !node.getNodeName().equals("#text");
    }

    public static boolean isValidNode(Node node, String name) {
        return node.getNodeName().equals(name);
    }
}