Here you can find the source of getPreviousElementNode(Node node)
private static Node getPreviousElementNode(Node node)
//package com.java2s; /******************************************************************************* * Copyright (c) 2001, 2009 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 * /* ww w.jav a 2 s. c o m*/ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { private static Node getPreviousElementNode(Node node) { Node previous = node.getPreviousSibling(); while (!(previous instanceof Element) && previous != null) { previous = previous.getPreviousSibling(); } if (previous instanceof Text) { return null; } return previous; } }