Java XML First Child Element getFirstLevelChildElements(Element parent)

Here you can find the source of getFirstLevelChildElements(Element parent)

Description

get First Level Child Elements

License

Open Source License

Declaration

public static final List<Element> getFirstLevelChildElements(Element parent) 

Method Source Code

//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 {
    public static final List<Element> getFirstLevelChildElements(Element parent) {
        NodeList nodeList = parent.getChildNodes();

        ArrayList<Element> childList = new ArrayList<Element>(nodeList.getLength());

        Node childNode = parent.getFirstChild();
        while (childNode != null) {
            if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                childList.add((Element) childNode);
            }/* ww  w  .j a  va  2  s  .c om*/
            childNode = childNode.getNextSibling();
        }

        return childList;
    }
}

Related

  1. getFirstElementChild(Node root)
  2. getFirstElementContent(Element element, String childName)
  3. getFirstElemText(Element parent, String childName)
  4. getFirstLevelChildElementByTagName(Element parent, String elementName)
  5. getFirstLevelChildElementByTagName(Element parent, String elementName)
  6. getFirstLevelChildElements(Element parent)
  7. getFirstLevelChildElementsByTagName(Element parent, String elementName)
  8. getFirstLevelChildElementsByTagName(Element parent, String elementName)
  9. getFirstMatchedValueByChildTagName(Node parent, String name)