Here you can find the source of getElementsOfNodeList(NodeList nodeList)
Parameter | Description |
---|---|
nodeList | The DOM node objects to extract elements from. |
@SuppressWarnings("unchecked") public static Element[] getElementsOfNodeList(NodeList nodeList)
//package com.java2s; /*-------------------------------------------------------------------------- * Copyright (c) 2004, 2006 OpenMethods, LLC * 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:/*from ww w .j a v a 2s . c om*/ * Trip Gilman (OpenMethods), Lonnie G. Pryor (OpenMethods), * Vincent Pruitt (OpenMethods) * * T.D. Barnes (OpenMethods) - initial API and implementation -------------------------------------------------------------------------*/ import java.util.Vector; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Returns an array containing the element objects in the provided node list. * * @param nodeList The DOM node objects to extract elements from. * @return The array of DOM elements found in the node list. */ @SuppressWarnings("unchecked") public static Element[] getElementsOfNodeList(NodeList nodeList) { Element[] ret = null; @SuppressWarnings("rawtypes") Vector v = new Vector(); for (int n = 0; n < nodeList.getLength(); n++) { Node item = nodeList.item(n); if (item.getNodeType() == Node.ELEMENT_NODE) { v.addElement(item); } } ret = new Element[v.size()]; for (int n = 0; n < ret.length; n++) { ret[n] = (Element) v.elementAt(n); } return ret; } }