Java XML Element Get by Name getGrandSonElementByTagName(Element element, String parentName, String eleName)

Here you can find the source of getGrandSonElementByTagName(Element element, String parentName, String eleName)

Description

get Grand Son Element By Tag Name

License

Open Source License

Declaration

public static Element getGrandSonElementByTagName(Element element, String parentName, String eleName) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {

    public static Element getGrandSonElementByTagName(Element element, String parentName, String eleName) {

        NodeList nl = element.getElementsByTagName(parentName);
        if (null == nl) {
            return null;
        }/*  w  w w.  j  a va  2  s  . co m*/
        Node item = nl.item(0);
        return getChildElementByTagName((Element) item, eleName);
    }

    public static Element getChildElementByTagName(Element ele, String childEleName) {

        NodeList nl = ele.getChildNodes();
        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())) {
                return (Element) node;
            }
        }
        return null;
    }
}

Related

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