Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /**
     * Returns the text associated to the given node
     * i.e. the value of the
     * @param node
     * @return
     */
    public static String getText(Node node) {
        Node textNode = node.getFirstChild();
        if (textNode == null) {
            return null;
        }
        short nodeType = textNode.getNodeType();
        if (nodeType != Node.TEXT_NODE && nodeType != Node.CDATA_SECTION_NODE) {
            return null;
        }
        return textNode.getNodeValue().trim();
    }
}