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.Element;

import org.w3c.dom.Node;

import org.w3c.dom.Text;

public class Main {
    /**
     * Get first Text node of the Element as String value
     * @param elem
     * @return
     */
    public static String getFirstTextValue(Element elem) {
        if (elem != null) {
            Node fc = elem.getFirstChild();
            if (null != fc && fc.getNodeType() == Node.TEXT_NODE) {
                return ((Text) fc).getData();
            }
        }
        return null;
    }
}