get Double from XML Element - Java XML

Java examples for XML:DOM Node Value

Description

get Double from XML Element

Demo Code


//package com.java2s;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static double getDouble(String sTag, Element eElement) {
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0)
                .getChildNodes();//from   w w  w . j av  a 2  s .co m
        Node nValue = (Node) nlList.item(0);
        double value = 0;
        try {
            value = Double.parseDouble(nValue.getNodeValue());
        } catch (Exception ex1) {
            System.out
                    .println("Exception at: com.alliancerational.parser.DocUtils(37): "
                            + ex1);
        }
        return value;
    }
}

Related Tutorials