Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.LinkedList;
import java.util.List;

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

public class Main {
    /**
     * @param node
     * @param name
     * @return all children nodes whose names contain <code>like</code>
     */
    public static List<Node> findChildrenLike(Node node, String like) {
        List<Node> ret = new LinkedList<Node>();
        NodeList nl = node.getChildNodes();
        int len = nl.getLength();
        Node child;
        for (int i = 0; i < len; i++) {
            child = nl.item(i);
            if (child.getNodeName().indexOf(like) > 0) {
                ret.add(child);
            }
        }
        return ret;
    }
}