Here you can find the source of getElement(String elementName, Element parentElement)
Parameter | Description |
---|---|
elementName | the element tag to serach for. |
parentElement | the parent element. |
public static Element getElement(String elementName, Element parentElement)
//package com.java2s; /******************************************************************************* * Copyright (c) 2002-2005 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 * * Contributors://w ww. j a v a 2 s . c o m * IBM - Initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { /** * Get the specified element from a parent element. * * @param elementName the element tag to serach for. * @param parentElement the parent element. * @return an element given the name and the parent element. */ public static Element getElement(String elementName, Element parentElement) { Element returnElement = null; NodeList nl; // Get the list of elements if ((nl = parentElement.getElementsByTagName(elementName)) != null) { // Return first element found returnElement = (Element) nl.item(0); } // Return element return returnElement; } }