Java XML Child Get getChildElements(Element element)

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

Description

get Child Elements

License

Open Source License

Declaration

public static List<Element> getChildElements(Element element) 

Method Source Code


//package com.java2s;
/*//from w w w . ja v  a  2s  . c  om
 * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
 *  
 *  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
 *  
 *  Contributors:
 *      Brad Davis - bradsdavis@gmail.com - Initial API and implementation
*/

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 {
    public static List<Element> getChildElements(Element element) {
        List<Element> elements = new LinkedList<Element>();

        NodeList children = element.getChildNodes();
        if (children == null) {
            return elements;
        }

        for (int i = 0, j = children.getLength(); i < j; i++) {
            Node child = children.item(i);

            if (child.getNodeType() == Node.ELEMENT_NODE) {
                elements.add((Element) child);
            }
        }

        return elements;
    }
}

Related

  1. getChildElements(Element element)
  2. getChildElements(Element element)
  3. getChildElements(Element element)
  4. getChildElements(Element element)
  5. getChildElements(Element element)
  6. getChildElements(Element element)
  7. getChildElements(Element parent)
  8. getChildElements(Element parent)
  9. getChildElements(Element parent)