Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static String getValue(Element e, String tagName) {
        try {
            // get node lists of a tag name from a Element
            NodeList elements = e.getElementsByTagName(tagName);

            if (elements.getLength() == 0) {
                return null;
            }
            Node node = elements.item(0);
            return node.getTextContent();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}