Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * XMLUtility.java  2/6/13 1:04 PM
 *
 * Copyright (C) 2012-2013 Nick Ma
 *
 * 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 3
 * of the License, or 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 java.util.ArrayList;

import java.util.Iterator;

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

public class Main {
    /**
     * Searches parent node for matching child nodes.
     *
     * @param node     The parent node
     * @param nodeName The child node's element name
     * @return A list of matching child Nodes
     */
    public static Iterator getNodes(Node node, String nodeName) {
        ArrayList nodes = new ArrayList();
        NodeList nl = node.getChildNodes();
        int nll = nl.getLength();
        for (int i = 0; i < nll; i++) {
            Node n = nl.item(i);
            if (n.getNodeName().equals(nodeName)) {
                nodes.add(n);
            }
        }
        return nodes.iterator();
    }
}