Java XML Element Get getElements(Element element, String tagName)

Here you can find the source of getElements(Element element, String tagName)

Description

get Elements

License

Apache License

Declaration

public static List<Element> getElements(Element element, 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.NodeList;

public class Main {

    public static List<Element> getElements(Element element, String tagName) {
        final NodeList nodeList = element.getElementsByTagName(tagName);
        return transElements(element, nodeList);
    }//from w ww .j  a va 2 s  . co  m

    public static List<Element> transElements(NodeList nodeList) {
        return transElements(null, nodeList);
    }

    public static List<Element> transElements(Element parentEle, NodeList nodeList) {
        final ArrayList<Element> elements = new ArrayList<Element>();
        int length = nodeList.getLength();
        for (int i = 0; i < length; i++) {
            Element element = (Element) nodeList.item(i);
            if (parentEle == null || element.getParentNode() == parentEle) {
                elements.add(element);
            }
        }

        return elements;
    }
}

Related

  1. getElementPosition(Element element)
  2. getElements(Element aElement)
  3. getElements(Element document, String elementName, String attrName, String attrValue)
  4. getElements(Element elem, String path)
  5. getElements(Element element)
  6. getElements(Element node)
  7. getElements(Element root)
  8. getElements(Element root, String element)
  9. getElements(Element root, String tagName)