Here you can find the source of getRootElement(final Element descendant)
Parameter | Description |
---|---|
descendant | The starting point for the parent chain traversal. |
public static Element getRootElement(final Element descendant)
//package com.java2s; // Licensed under the MIT license. See License.txt in the repository root. import org.w3c.dom.Element; public class Main { /**/*ww w. ja va2 s.c om*/ * Walks the parent chain from the specified element to find the root node. * * @param descendant * The starting point for the parent chain traversal. * * @return The root node of the document. */ public static Element getRootElement(final Element descendant) { Element element = descendant; while (element.getParentNode() != null && element.getParentNode() instanceof Element) { element = (Element) element.getParentNode(); } return element; } }