Here you can find the source of getPrevSibling(Element element)
Parameter | Description |
---|---|
element | The element to search siblings for. |
public static Element getPrevSibling(Element element)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * 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:/*from w w w .j a v a 2 s .co m*/ * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ import org.w3c.dom.*; public class Main { /** * Get the previous sibling element of the specified element, null if it has no previous other siblings. * * @param element The element to search siblings for. * @return The previous sibling element, null if it has none. */ public static Element getPrevSibling(Element element) { if (element == null) return null; Node node = element.getPreviousSibling(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; node = node.getPreviousSibling(); } return null; } }