Java XML First Child Element getFirstChildElement(Element parent)

Here you can find the source of getFirstChildElement(Element parent)

Description

get First Child Element

License

Apache License

Declaration

public static Element getFirstChildElement(Element parent) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static Element getFirstChildElement(Element elem, String name) {
        NodeList elems = elem.getElementsByTagName(name);
        return (Element) elems.item(0);
    }/*from   ww w  .j  a v  a 2s  . c o m*/

    public static Element getFirstChildElement(Element parent) {
        NodeList children = parent.getChildNodes();
        if (children.getLength() == 0)
            return null;
        for (int k = 0; k < children.getLength(); k++) {
            Node kid = children.item(k);
            if (kid instanceof Element) {
                return (Element) kid;
            }
        }
        return null;
    }
}

Related

  1. getFirstChildElement(Element element, String namespaceURI, String tagName)
  2. getFirstChildElement(Element elm, String name)
  3. getFirstChildElement(Element elm, String name)
  4. getFirstChildElement(Element elm, String name)
  5. getFirstChildElement(Element parent)
  6. getFirstChildElement(Element parent)
  7. getFirstChildElement(Element parent, String childName)
  8. getFirstChildElement(Element parent, String nsUri, String localPart)
  9. getFirstChildElement(Element parent, String tagName)