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 {
    /**
     * Returns an array of all the Element children of a DOM node.
     *
     * @param  parent  parent node
     * @return  children array
     */
    public static Element[] getChildren(Node parent) {
        NodeList nodeList = parent.getChildNodes();
        int nnode = nodeList.getLength();
        List elList = new ArrayList(nnode);
        for (int i = 0; i < nnode; i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                elList.add((Element) node);
            }
        }
        return (Element[]) elList.toArray(new Element[0]);
    }
}