Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

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

public class Main {
    public static List<String> getByName(String name, Element node) {
        List<String> r = new ArrayList<String>();
        List<Element> l = getRealChilds(node);
        for (Element n : l) {
            if (n.getNodeName().equals(name)) {
                r.add(n.getTextContent());
            }
        }
        return r;
    }

    public static List<Element> getRealChilds(Node node) {
        List<Element> interlayer = new ArrayList<Element>();
        NodeList l = node.getChildNodes();
        for (int i = 0; i < l.getLength(); i++) {
            Node n = l.item(i);
            if (n instanceof Element) {
                interlayer.add(((Element) n));
            }
        }
        return interlayer;
    }
}