Java XML Node Find findAllNodes(Node node, String[] nodeNames, ArrayList results)

Here you can find the source of findAllNodes(Node node, String[] nodeNames, ArrayList results)

Description

find All Nodes

License

Open Source License

Declaration

static private void findAllNodes(Node node, String[] nodeNames,
            ArrayList results) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2003, 2006 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:/*from w  w w.  j a va 2 s .  c o  m*/
 * IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.ArrayList;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    static private void findAllNodes(Node node, String[] nodeNames,
            ArrayList results) {

        NodeList nodes = node.getChildNodes();
        if (nodes != null) {
            for (int i = 0; i < nodes.getLength(); i++) {
                for (int j = 0; j < nodeNames.length; j++) {
                    if (nodes.item(i).getNodeName().equals(nodeNames[j])) {
                        results.add(nodes.item(i));
                    }
                }
                findAllNodes(nodes.item(i), nodeNames, results);
            }
        }
    }
}

Related

  1. findAllDescendantElements(Node e, String qname, Collection vector)
  2. findAllNodesRecursive(Node n, String name)
  3. findAllProcessingIstructions(Node node, String name, List result)
  4. findAllUrisRecursive(Node node, List nodes)
  5. findElement(Node node, String tagName)