Java XML Child Get by Name getChildElement(Element parent, String childName)

Here you can find the source of getChildElement(Element parent, String childName)

Description

get Child Element

License

Open Source License

Declaration

public static Element getChildElement(Element parent, String childName) 

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 getChildElement(Element parent, String childName) {
        NodeList children = parent.getChildNodes();
        int size = children.getLength();

        for (int i = 0; i < size; i++) {
            Node node = children.item(i);

            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;

                if (childName.equals(element.getNodeName())) {
                    return element;
                }//  ww w.j  a v  a  2 s  .  c o  m
            }
        }

        return null;
    }
}

Related

  1. getChildElement(Element element, String name)
  2. GetChildElement(Element element, String name)
  3. getChildElement(Element element, String tagName)
  4. getChildElement(Element element, String tagName)
  5. getChildElement(Element parent, String childName)
  6. getChildElement(Element parent, String element)
  7. getChildElement(Element parent, String name)
  8. getChildElement(Element parent, String name)
  9. getChildElement(Element parent, String name)