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 float getTagValueAsFloat(Document document, String tagName) {
        float tagValue = -1.0f;

        String tempVal = getTagValueAsString(document, tagName);
        tagValue = Float.parseFloat(tempVal);

        return tagValue;
    }

    /**
     *
     * @param document
     * @param tagName
     * @return
     */
    public static String getTagValueAsString(Document document, String tagName) {
        if (document == null || tagName == null || tagName.length() == 0)
            return null;

        String tagValue = null;
        NodeList nlist = null;
        Element element = null;

        Element root = document.getDocumentElement();

        nlist = root.getElementsByTagName(tagName);
        element = (Element) nlist.item(0);
        if (element.hasChildNodes()) {
            tagValue = element.getFirstChild().getNodeValue();
        }
        return tagValue;
    }
}