Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 XMLUtils.java
    
 (c) 2010-2011 Edward Swartz
    
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/epl-v10.html
 */

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 {
    /**
     * Get the Element children of an element as an array.
     * @param element
     * @return non-<code>null</code> array 
     */
    public static Element[] getChildElements(Element element) {
        NodeList childNodes = element.getChildNodes();
        List<Element> kids = new ArrayList<Element>();
        Node node = childNodes.item(0);
        while (node != null) {
            if (node instanceof Element) {
                kids.add((Element) node);
            }
            node = node.getNextSibling();
        }
        return (Element[]) kids.toArray(new Element[kids.size()]);
    }
}