Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**
     * Given an node, returns the child text node of this element.
     * 
     * @param node
     *            the node to get the text node from
     * @return the text node that is a child of this node, or <CODE>null</CODE>
     *         if there is no such child
     */
    public static String containedText(Node node) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node c = children.item(i);
            if (c.getNodeType() != Node.TEXT_NODE)
                continue;
            return ((Text) c).getData();
        }
        return null;
    }
}