Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.CDATASection;

import org.w3c.dom.Node;
import org.w3c.dom.Text;

public class Main {

    public static String getTextData(Node node) {
        if (!node.hasChildNodes()) {
            return null;
        }
        Node child = node.getFirstChild();
        while (child != null && child.getNodeType() != Node.TEXT_NODE
                && child.getNodeType() != Node.CDATA_SECTION_NODE) {
            child = child.getNextSibling();
        }
        if (child == null) {
            return null;
        }

        if (child.getNodeType() == Node.TEXT_NODE) {
            return ((Text) child).getData();
        } else {
            return ((CDATASection) child).getData();
        }

    }
}