Java XML First Child Element getFirstChildByName(Element parent, String name)

Here you can find the source of getFirstChildByName(Element parent, String name)

Description

Return the first child element with a given name.

License

Apache License

Parameter

Parameter Description
parent parent element
name child element name

Declaration

public static Element getFirstChildByName(Element parent, String name) 

Method Source Code


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

import org.w3c.dom.*;

public class Main {
    /**/*  w ww.  j a  va2  s  . co  m*/
     * Return the first child element with a given name.  
     * @param parent parent element
     * @param name child element name
     * @return 
     */
    public static Element getFirstChildByName(Element parent, String name) {
        NodeList children = parent.getElementsByTagName(name);
        if (children.getLength() == 0) {
            return null;
        }
        return (Element) children.item(0);
    }
}

Related

  1. getFirstChild(final Element el, final String name)
  2. getFirstChild(final Element parent, final String childName)
  3. getFirstChild(final Element parentElem, final String childName)
  4. getFirstChild(Node node, String childName)
  5. getFirstChild(Node parent)
  6. getFirstChildByNodeName(Node parent, String nodeName)
  7. getFirstChildByNS(Element node, String ns, String localName)
  8. getFirstChildByRegex(Element ele, String pattern)
  9. getFirstChildByTagName(Element parent, String tagName)