Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2002-2005 IBM Corporation and others. * 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: * IBM - Initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * Find the previous sibling element. * * @param startNode XML start node. * @return the previous sibling element. */ public static Element findPreviousSibling(Node startNode) { if (startNode == null) return null; while (startNode != null) { startNode = startNode.getPreviousSibling(); if (startNode == null) return null; if (startNode.getNodeType() == Node.ELEMENT_NODE) return (Element) startNode; } return null; } }