Java XML Element Root getRootElement(final Element descendant)

Here you can find the source of getRootElement(final Element descendant)

Description

Walks the parent chain from the specified element to find the root node.

License

Open Source License

Parameter

Parameter Description
descendant The starting point for the parent chain traversal.

Return

The root node of the document.

Declaration

public static Element getRootElement(final Element descendant) 

Method Source Code

//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;
    }
}

Related

  1. getRootElement(Document doc)
  2. getRootElement(Document doc)
  3. getRootElement(Document document)
  4. getRootElement(Document document)
  5. getRootElement(Document parent)
  6. getRootElement(final File definition)
  7. getRootElement(final String respuestaPost)
  8. getRootElement(final XMLEventReader bufferedXmlEventReader)
  9. getRootElement(String elementName, String namespace, String prefix)