Here you can find the source of getElement(Element element, boolean before)
Parameter | Description |
---|---|
element | a parameter |
before | true to search the element before, false for the element after |
public static Element getElement(Element element, boolean before)
//package com.java2s; /****************************************************************************** * Copyright (c) 2008-2013, Linagora//ww w. j a v a 2 s.c o m * * 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: * Linagora - initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { /** * @param element * @param before true to search the element before, false for the element after * @return the element before <i>element</i> */ public static Element getElement(Element element, boolean before) { NodeList bas = element.getParentNode().getChildNodes(); Element searchedElement = null; boolean found = false; for (int i = 0; i < bas.getLength() && (searchedElement == null || !found); i++) { if (element.equals(bas.item(i))) found = true; else if (bas.item(i) instanceof Element) { // We look for the element before - we didn't find the right element yet if (before && !found) searchedElement = (Element) bas.item(i); // We look for the element after - we have to find the right element first else if (!before && found) searchedElement = (Element) bas.item(i); } } return searchedElement; } }