Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Element;

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

public class Main {

    private static List<Node> getNode(Element element, String nodeWeiZhi) {
        List<Node> notes = new ArrayList<Node>();
        String[] nodeNames = nodeWeiZhi.split(">");
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            String nodeName = node.getNodeName();
            if (nodeName.equals(nodeNames[0])) {
                if (nodeNames.length == 1) {
                    notes.add(node);
                }
                String nodeWeiZhiTemp = nodeWeiZhi.replaceFirst(nodeNames[0], "").replaceFirst(">", "");
                NodeList childrenTempList = node.getChildNodes();
                if (childrenTempList.getLength() > 0 && !nodeWeiZhiTemp.equals("")) {
                    notes.addAll(getNode((Element) node, nodeWeiZhiTemp));
                }
            }
        }
        return notes;
    }
}