Java XML Child Get getChildElements(Element e, String tag)

Here you can find the source of getChildElements(Element e, String tag)

Description

get Child Elements

License

Open Source License

Declaration

public static List<Element> getChildElements(Element e, String tag) 

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 List<Element> getChildElements(Element e, String tag) {
        NodeList children = e.getElementsByTagName(tag);
        if (children == null || children.getLength() == 0)
            return null;

        List<Element> result = new ArrayList<Element>();
        for (int index = 0; index < children.getLength(); index++) {
            Node n = children.item(index);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                result.add((Element) n);
            }/*from w  w w .  j a va  2s. co m*/
        }
        return result;
    }
}

Related

  1. getChild(Node node, String name, String attrName, String attrValue)
  2. getChild(Node parent, String name)
  3. getChild(Node parent, String name)
  4. getChildElements(Element e)
  5. getChildElements(Element e)
  6. getChildElements(Element el)
  7. getChildElements(Element ele)
  8. getChildElements(Element ele)
  9. getChildElements(Element ele)