Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* $This file is distributed under the terms of the license in /doc/license.txt$ */

import org.w3c.dom.Document;

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

public class Main {
    /**
     * @param document
     * @param name
     * @return
     */
    public static String getElementByName(Document document, String name) {
        NodeList nodes = document.getElementsByTagName(name);
        String s = null;
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            s = node.getTextContent().trim();
        }
        return s;
    }
}