Java XML NodeList getElementsOfNodeList(NodeList nodeList)

Here you can find the source of getElementsOfNodeList(NodeList nodeList)

Description

Returns an array containing the element objects in the provided node list.

License

Open Source License

Parameter

Parameter Description
nodeList The DOM node objects to extract elements from.

Return

The array of DOM elements found in the node list.

Declaration

@SuppressWarnings("unchecked")
public static Element[] getElementsOfNodeList(NodeList nodeList) 

Method Source Code

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

Related

  1. getElementFromItem(NodeList list, int index)
  2. getElementFromNodeList(NodeList nl)
  3. getElementList(NodeList list)
  4. getElements(NodeList nodeList, String localname, String namespaceURI)
  5. getElementsFromNodeList(final NodeList nodeList)
  6. getEnvVariableMap(NodeList nodes)
  7. getFirst(NodeList nodes)
  8. getFirstElement(NodeList list)
  9. getFirstElement(NodeList list)