Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static String getFirstElementText(Document parent, String tag) {
        NodeList nl = parent.getElementsByTagName(tag);
        if (nl.getLength() > 0) {
            return ((Element) nl.item(0)).getTextContent();
        }
        return null;
    }

    public static String getFirstElementText(Element parent, String tag) {
        NodeList nl = parent.getElementsByTagName(tag);
        if (nl.getLength() > 0) {
            return ((Element) nl.item(0)).getTextContent();
        }
        return null;
    }
}