Java Swing HTML findElementDown(final String name, final Element parent)

Here you can find the source of findElementDown(final String name, final Element parent)

Description

find the first occurrence of an Element in the element tree below a given Element

License

Open Source License

Parameter

Parameter Description
name the name of the <code>Element</code> to search for
parent the <code>Element</code> to start looking

Return

the found Element or null if none is found

Declaration

public static Element findElementDown(final String name, final Element parent) 

Method Source Code

//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;
    }
}

Related

  1. addToContentModels(DTD dtd, Element existing, Element alt)
  2. containsAttribute(Element element, Object name, Object value)
  3. findElementUp(final String name1, final String name2, final Element start)
  4. findLinkElementUp(Element elem)
  5. findLinkUp(Element elem)
  6. getHTMLFromXML(String xml, URL xsl)