Java XML Node Parent getFirstElement(Node xml)

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

Description

get First Element

License

Open Source License

Declaration

public static final Node getFirstElement(Node xml) 

Method Source Code


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

import java.util.Optional;
import org.w3c.dom.Node;

public class Main {
    public static final Node getFirstElement(Node xml) {
        if (Node.DOCUMENT_NODE == xml.getNodeType()) {
            xml = xml.getFirstChild();/*from  ww w. ja va2  s .c  om*/
        }
        if (Optional.ofNullable(xml.getNamespaceURI()).orElse("").trim().equals("")) {
            throw new IllegalArgumentException("Namespace URI cannot be null!");
        }
        return xml;
    }
}

Related

  1. getFirstElement(Node element)
  2. getFirstElement(Node node, String namespace, String name)
  3. getFirstElementByTagName(Node node, String tagName)
  4. getFirstElementByTagName(Node node, String tagName)
  5. getFirstElementWithTagName(Node node, String element)
  6. getFirstNamedNode(Node node, String name)