Java XML Child Get by Name getChildElementsByTagName(Element ele, String childEleName)

Here you can find the source of getChildElementsByTagName(Element ele, String childEleName)

Description

get Child Elements By Tag Name

License

Open Source License

Declaration

public static List<Node> getChildElementsByTagName(Element ele, String childEleName) 

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<Node> getChildElementsByTagName(Element ele, String childEleName) {

        NodeList nl = ele.getChildNodes();
        List<Node> childEles = new ArrayList<Node>();
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element && childEleName.equals(node.getNodeName())
                    || childEleName.equals(node.getLocalName())) {
                childEles.add(node);//w  w w.j  a  v  a  2 s.c om
            }
        }
        return childEles;
    }
}

Related

  1. getChildElementsByName(Element parent, String name)
  2. getChildElementsByName(Element parent, String name)
  3. getChildElementsByName(Element parent, String tagName)
  4. getChildElementsByName(Element root, String tagName)
  5. getChildElementsByName(final Element parent, final String name)
  6. getChildElementsByTagName(Element ele, String childEleName)
  7. getChildElementsByTagName(Element ele, String childEleName, boolean localName)
  8. getChildElementsByTagName(Element elem, String name)
  9. getChildElementsByTagName(Element element, String name)