Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /** Takes the parsed XML representation (i.e. Document) and a string (e.g <variable> in a <query> message)
     * @param document - the parsed XML represenation
     * @param tagName - the name of the data item whose value is desired
     * @return The string that is that value*/
    public static String GetValueForNode(Document document, String tagName) {
        NodeList nodes = document.getElementsByTagName(tagName);
        if (nodes == null)
            return (null);
        else {
            Node n = nodes.item(0);
            String value = n.getFirstChild().getNodeValue();
            if (value == null)
                return null;
            else
                return value.trim();
        }
    }
}