Here you can find the source of findElementDown(final String name, final Element parent)
Element
in the element tree below a given Element
Parameter | Description |
---|---|
name | the name of the <code>Element</code> to search for |
parent | the <code>Element</code> to start looking |
Element
or null if none is found
public static Element findElementDown(final String name, final Element parent)
//package com.java2s; /*//from w w w.j ava 2 s . c om * SimplyHTML, a word processor based on Java, HTML and CSS * Copyright (C) 2002 Ulrich Hilger * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import javax.swing.text.Element; import javax.swing.text.ElementIterator; public class Main { /** * find the first occurrence of an <code>Element</code> in the * element tree below a given <code>Element</code> * * @param name the name of the <code>Element</code> to search for * @param parent the <code>Element</code> to start looking * * @return the found <code>Element</code> or null if none is found */ public static Element findElementDown(final String name, final Element parent) { Element foundElement = null; final ElementIterator eli = new ElementIterator(parent); Element thisElement = eli.first(); while (thisElement != null && foundElement == null) { if (thisElement.getName().equalsIgnoreCase(name)) { foundElement = thisElement; } thisElement = eli.next(); } return foundElement; } }