Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// are made available under the terms of the Eclipse Public License v1.0

import org.w3c.dom.Element;

public class Main {
    /**
     * text of a leaf node, without child element
     * 
     * @param tag
     * @return String
     */
    public static String getNodeText(Element tag) {
        String text = tag.toString();
        int i = text.indexOf(">"); //$NON-NLS-1$
        int j = text.lastIndexOf("</"); //$NON-NLS-1$
        if (i < 0 || j < 0 || j < i) {
            return ""; //$NON-NLS-1$
        }

        return text.substring(i + 1, j);
    }
}