Here you can find the source of getNextSibling(Element h2)
public static Element getNextSibling(Element h2)
//package com.java2s; /**/*from w w w . ja va2 s . co m*/ * Copyright (c) 2013-2014 Angelo ZERR. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation */ import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static Element getNextSibling(Element h2) { Node node = h2.getNextSibling(); while (node != null && node.getNodeType() != Node.ELEMENT_NODE) { node = node.getNextSibling(); } return getElement(node); } public static Element getElement(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { return (Element) node; } return null; } }