Java XML NodeList getNodeFromNodeList(NodeList nl, String nodeName, int index)

Here you can find the source of getNodeFromNodeList(NodeList nl, String nodeName, int index)

Description

Gets a named node from a node list.

License

Open Source License

Parameter

Parameter Description
nl The node list
nodeName The node name

Return

The node named nodeName

Declaration

public static Node getNodeFromNodeList(NodeList nl, String nodeName,
        int index) 

Method Source Code

//package com.java2s;
/*/*  w w w .jav a 2s. c o m*/
 *  Copyright (C) 2003 by Francois Guillet
 *  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.
 */

import org.w3c.dom.*;

public class Main {
    /**
     *  Gets a named node from a node list. Returns null if the node does not
     *  exist.
     *
     *@param  nl        The node list
     *@param  nodeName  The node name
     *@return           The node named nodeName
     */
    public static Node getNodeFromNodeList(NodeList nl, String nodeName,
            int index) {
        for (int i = 0; i < nl.getLength(); ++i) {
            Node n = nl.item(i);
            if (n.getNodeName().equals(nodeName)) {
                if (index-- == 0)
                    return n;
            }
        }
        return null;
    }
}

Related

  1. getMethodNames(NodeList methodNodes)
  2. getNode(NodeList nodes, String tagName)
  3. getNode(String tagName, NodeList nodes)
  4. getNodeByNodeName(NodeList nodes, String nodeName)
  5. getNodeFromNodeList(NodeList list, String name)
  6. getNodeFromNodeList(NodeList nodeList)
  7. getNodeIntValue(String tagName, NodeList nodes)
  8. getNodeList(Element from, String elementName)
  9. getNodeList(Node fatherNode, String nodeName)