Here you can find the source of getFirstElementSibling(Node node)
Parameter | Description |
---|---|
node | the node whose siblings (including itself) you are interested in. May be <tt>null</tt> |
public static Element getFirstElementSibling(Node node)
//package com.java2s; //License from project: LGPL import org.w3c.dom.*; public class Main { /**//from w w w .java 2s. c om * Returns the first subsequent sibling of a given node which is an Element. * This is useful for naviating a DOM as a tree of elements when * the presence of text or attribute children is a distraction. * * @param node the node whose siblings (including itself) you are * interested in. May be <tt>null</tt> * @return the first sibling of <tt>node</tt> which is an Element. * If <tt>node</tt> itself is an element, that is returned. * If <tt>node</tt> has no subsequent siblings which are * elements, or if it is <tt>null</tt>, * then <tt>null</tt> is returned. */ public static Element getFirstElementSibling(Node node) { return (node == null || node instanceof Element) ? (Element) node : getFirstElementSibling(node.getNextSibling()); } }