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 Element getChildNode(Element parent, String name) {
        List<Element> childNodes = getChildNodes(parent, name);
        if (childNodes.isEmpty()) {
            return null;
        }
        return childNodes.get(0);
    }

    public static List<Element> getChildNodes(Element parent, String name) {
        List<Element> result = new ArrayList<Element>();
        NodeList childNodes = parent.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node n = childNodes.item(i);
            if (name.equals(n.getNodeName())) {
                result.add((Element) n);
            }
        }
        return result;
    }
}