Java XML Element Get getElementList(Element element)

Here you can find the source of getElementList(Element element)

Description

get Element List

License

Open Source License

Declaration

protected static List<Element> getElementList(Element element) 

Method Source Code


//package com.java2s;
/*// www  .ja v a2  s  .com
 * CDDL HEADER START
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 * http://www.sun.com/cddl/cddl.html and legal/CDDLv1.0.txt
 * See the License for the specific language governing
 * permission and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at legal/CDDLv1.0.txt.
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 *
 * Copyright 2009 Sun Microsystems Inc. All Rights Reserved
 * CDDL HEADER END
 */

import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

import org.w3c.dom.Element;

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

public class Main {
    protected static List<Element> getElementList(Element element) {
        if (element == null) {
            return Collections.emptyList();
        }

        NodeList childNodes = element.getChildNodes();
        int numChildren = childNodes.getLength();

        List<Element> elementList = new ArrayList<Element>(numChildren);

        for (int i = 0; i < numChildren; i++) {
            Node childNode = childNodes.item(i);
            if (childNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            elementList.add((Element) childNode);
        }

        return elementList;
    }
}

Related

  1. getElementLanguage(Element elemNode, String defaultLangCode)
  2. getElementLanguage(Element elemNode, String defaultLangCode)
  3. getElementList(Document doc, String expression)
  4. getElementList(Element dataRoot, String name)
  5. getElementList(Element dataRoot, String name)
  6. getElementList(Element element, String name)
  7. getElementList(final Element element)
  8. getElementLocalName(Element element)
  9. getElementName(Class claz)