Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Element;

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

public class Main {

    private static String getNodeText(Element element, String nodeWeiZhi) {
        String result = "";
        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) {
                    result += "," + node.getTextContent().trim();
                }
                String nodeWeiZhiTemp = nodeWeiZhi.replaceFirst(nodeNames[0], "").replaceFirst(">", "");
                NodeList childrenTempList = node.getChildNodes();
                if (childrenTempList.getLength() > 0 && !nodeWeiZhiTemp.equals("")) {
                    result += getNodeText((Element) node, nodeWeiZhiTemp);
                }
            }
        }
        return result;
    }
}