Java XML First Child Element getFirstLevelChildElementByTagName(Element parent, String elementName)

Here you can find the source of getFirstLevelChildElementByTagName(Element parent, String elementName)

Description

get First Level Child Element By Tag Name

License

Open Source License

Declaration

public static final Element getFirstLevelChildElementByTagName(Element parent, String elementName) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static final Element getFirstLevelChildElementByTagName(Element parent, String elementName) {
        Node childNode = parent.getFirstChild();
        while (childNode != null) {
            if ((childNode.getNodeType() == Node.ELEMENT_NODE)
                    && ((Element) childNode).getLocalName().equals(elementName)) {
                return (Element) childNode;
            }/* w  w  w.  j a  v a  2s  .c om*/
            childNode = childNode.getNextSibling();
        }
        return null;
    }
}

Related

  1. getFirstElementChild(final Node node)
  2. getFirstElementChild(Node root)
  3. getFirstElementContent(Element element, String childName)
  4. getFirstElemText(Element parent, String childName)
  5. getFirstLevelChildElementByTagName(Element parent, String elementName)
  6. getFirstLevelChildElements(Element parent)
  7. getFirstLevelChildElements(Element parent)
  8. getFirstLevelChildElementsByTagName(Element parent, String elementName)
  9. getFirstLevelChildElementsByTagName(Element parent, String elementName)