get XML Elements By Tag Name - Android XML

Android examples for XML:XML Element

Description

get XML Elements By Tag Name

Demo 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> getElementsByTagName(Element element,
            String name) {// w  ww . ja  v  a  2s  .c om
        List<Element> elementList = new ArrayList<Element>();
        NodeList nodeList = element.getElementsByTagName(name);
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                elementList.add((Element) node);
            }
        }
        return elementList;
    }
}

Related Tutorials