Here you can find the source of getFirstElement(Node xml)
public static final Node getFirstElement(Node xml)
//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; } }