Here you can find the source of findElement(NodeList elements, String elementName)
Parameter | Description |
---|---|
elements | the NodeList of elements to search |
elementName | the name of the Element to look for |
public static Element findElement(NodeList elements, String elementName)
//package com.java2s; /*/* ww w.jav a2s.c o m*/ * This file is part of "Tweety", a collection of Java libraries for * logical aspects of artificial intelligence and knowledge representation. * * Tweety is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * 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, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Find an {@code Element} of a given name in a {@code NodeList} * @param elements the {@code NodeList} of elements to search * @param elementName the name of the {@code Element} to look for * @return the {@code Element} if found, otherwise {@code null} */ public static Element findElement(NodeList elements, String elementName) { for (int i = 0; i < elements.getLength(); i++) { Node currentNode = elements.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { Element currentElement = (Element) currentNode; if (currentNode.getNodeName().equals(elementName)) { return currentElement; } } } return null; } }