Java XML Element Get by Name getGrandSonElementsByTagName(Element ele, String parentName, String eleName)

Here you can find the source of getGrandSonElementsByTagName(Element ele, String parentName, String eleName)

Description

get Grand Son Elements By Tag Name

License

Open Source License

Declaration

public static List<Node> getGrandSonElementsByTagName(Element ele, String parentName, String eleName) 

Method Source Code


//package com.java2s;

import org.w3c.dom.*;

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<Node> getGrandSonElementsByTagName(Element ele, String parentName, String eleName) {

        NodeList nl = ele.getElementsByTagName(parentName);
        if (null == nl) {
            return null;
        }/*from  ww  w  .  jav  a 2 s.c om*/
        Node item = nl.item(0);
        if (null == item) {
            return null;
        }
        NodeList subNodeList = item.getChildNodes();
        List<Node> childEles = new ArrayList<Node>();
        Node node = null;
        for (int i = 0; i < subNodeList.getLength(); i++) {
            node = subNodeList.item(i);

            if (node != null) {
                if (node instanceof Element && eleName.equals(node.getNodeName())
                        || eleName.equals(node.getLocalName())) {
                    childEles.add(node);
                }
            }
        }

        return childEles;
    }
}

Related

  1. getFirstElementAtAnyDepthByNodeName(Element parent, String name)
  2. getFirstElementByName(Element parent, String name)
  3. getFirstElementByName(String name, Element parent)
  4. getFirstElementByTagName(Element parent, String tagName)
  5. getGrandSonElementByTagName(Element element, String parentName, String eleName)
  6. getGrandSonElementValueByTagName(Element element, String parentName, String eleName)
  7. getGrandSonListValueByTagName(Element element, String parentName, String eleName)
  8. getValue(Document doc, String Tag)
  9. getValue(Document doc, String tagName)