Android XML Node Child Get getChildElementsByName(Element parent, String name)

Here you can find the source of getChildElementsByName(Element parent, String name)

Description

get Child Elements By Name

Declaration

public static List<Element> getChildElementsByName(Element parent,
            String name) 

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> getChildElementsByName(Element parent,
            String name) {/*from   w  w w . j av  a 2 s .  co m*/
        List<Element> result = new ArrayList<Element>();
        NodeList childNodes = parent.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = childNodes.item(i);
            if (child.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            String nodeName = child.getNodeName();
            if (name.equals(nodeName.trim())) {
                result.add((Element) child);
            }
        }
        return result;
    }
}

Related

  1. getChildElement(Node element, String childNodeName)
  2. getChildElement(Node element, String childNodeName)
  3. getChildElementText(Node element, String childNodeName)
  4. getChildElementText(Node element, String childNodeName)
  5. getChildElements(Node node)
  6. getChildNodes(Node node, short type)
  7. getChildTagValue(Node node, String tag)
  8. getChildText(Node n)
  9. getChildren(Node node, String name)