Here you can find the source of getRootElement(Document parent)
Parameter | Description |
---|---|
parent | the document |
public static Element getRootElement(Document parent)
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**//from w w w .j av a2 s.com * Gets the root element of a document. * @param parent the document * @return the root element */ public static Element getRootElement(Document parent) { return getFirstChildElement((Node) parent); } /** * Gets the first child element of an element. * @param parent the parent element * @return the first child element or null if there are no child elements */ public static Element getFirstChildElement(Element parent) { return getFirstChildElement((Node) parent); } /** * Gets the first child element of a node. * @param parent the node * @return the first child element or null if there are no child elements */ private static Element getFirstChildElement(Node parent) { NodeList nodeList = parent.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { return (Element) node; } } return null; } }