Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * Returns a list of the direct child {@link Element}s of the given parent.
     * 
     * @param parent The parent element.
     */
    public static List<Element> getChildElements(Element parent) {
        List<Element> childElements = new LinkedList<Element>();
        NodeList childNodes = parent.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if (childNode instanceof Element)
                childElements.add((Element) childNode);
        }
        return childElements;
    }
}