Java XML Element Get from Parent getFirstElement(Node parent)

Here you can find the source of getFirstElement(Node parent)

Description

Gets the first element of a Node

License

Apache License

Parameter

Parameter Description
parent Node

Return

first element of a Node

Declaration

public static Element getFirstElement(Node parent) 

Method Source Code

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

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

public class Main {
    /**//  www  . j a va  2s . com
     * Gets the first element of a Node
     * @param parent Node
     * @return first element of a Node
     */
    public static Element getFirstElement(Node parent) {
        Node n = parent.getFirstChild();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }
        if (n == null) {
            return null;
        }
        return (Element) n;
    }
}

Related

  1. getElements(Document document, Element parent)
  2. getElements(Document document, Element parent)
  3. getElementStringValue(Document document, Element parent, String element)
  4. getElementValueByTagName(Document doc, String parentName, String eleName)
  5. getFirstElement(Node parent)
  6. getFirstNode(final Node parent, final String... path)
  7. getNamedElemValue(Element parent, String elementName)
  8. getNamedNodeList(Element parent, String containerTagName)
  9. getNamespacePrefix(Node parentNode, String preferredPrefix, String nsUri)