Java XML Child Get getChild(Element node, String tagName)

Here you can find the source of getChild(Element node, String tagName)

Description

get Child

License

Open Source License

Declaration

public static Element getChild(Element node, String tagName) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Element getChild(Element node, String tagName) {
        Element element = null;/*from w w  w .  j a  v a 2 s .  co  m*/

        do {
            if (node == null) {
                break;
            }

            NodeList childNodes = node.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node child = childNodes.item(i);

                if (child.getNodeType() == Node.ELEMENT_NODE) {
                    if (child.getNodeName().equals(tagName)) {
                        element = (Element) child;
                        break;
                    }
                }
            }
        } while (false);

        return element;
    }
}

Related

  1. getChild(Element el, String name)
  2. getChild(Element element, String child)
  3. getChild(Element element, String name)
  4. getChild(Element element, String name)
  5. getChild(Element element, String name)
  6. getChild(Element parent, int i)
  7. getChild(Element parent, String element)
  8. getChild(Element parent, String name)
  9. getChild(Element parent, String name)