Java XML Child Get by Name getChildElements(Element parent, String tagName)

Here you can find the source of getChildElements(Element parent, String tagName)

Description

get Child Elements

License

Apache License

Declaration

public static List<Element> getChildElements(Element parent, String tagName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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 parent, String tagName) {
        NodeList nodes = parent.getElementsByTagName(tagName);
        List<Element> elements = new ArrayList();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (((node instanceof Element)) && (node.getParentNode() == parent)) {
                elements.add((Element) node);
            }/*w  ww  . ja v a 2 s  .  c  o m*/
        }
        return elements;
    }
}

Related

  1. getChildElements(Element parent, String name)
  2. getChildElements(Element parent, String name)
  3. getChildElements(Element parent, String name)
  4. getChildElements(Element parent, String nsUri, String localPart)
  5. getChildElements(Element parent, String nsUri, String localPart)
  6. getChildElements(Element parent, String tagName)
  7. getChildElements(Element parent, String tagName)
  8. getChildElements(Element parent, String tagName)
  9. getChildElementsByName(Element element, String localName)