Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * XmlUtil.java
 *
 * (c) 2009  The Echo Nest
 * See "license.txt" for terms
 *
 *
 */

import java.io.IOException;

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

public class Main {
    public static float getDescendentTextAsFloat(Node node, String name, float defaultValue) throws IOException {
        Node d = getDescendent(node, name);
        if (d != null) {
            String sval = d.getTextContent().trim();
            return Float.parseFloat(sval);
        }
        return defaultValue;
    }

    public static Node getDescendent(Node node, String nodeName) throws IOException {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeName().equals(nodeName)) {
                return child;
            }
        }
        return null;
    }
}