Java XML Node Value nodeToDouble(Node node)

Here you can find the source of nodeToDouble(Node node)

Description

Converts a node to a double

License

Open Source License

Parameter

Parameter Description
node The node to be parsed

Return

The obtained value

Declaration

protected static Double nodeToDouble(Node node) 

Method Source Code

//package com.java2s;
/**/* w  w  w  .ja  v a 2  s  .  c o  m*/
 * Copyright (c) 2006, 2009 Hugo Corbucci and others.<br>
 * All rights reserved. This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html<br>
 * <br>
 * Contributors:<br>
 * Mariana V. Bravo - initial API and implementation<br>
 * Victor D. Lopes, Hugo Corbucci - later contributions<br>
 * <br>
 * This file was created on 2006/09/10, 10:04:05, by Victor D. Lopes.<br>
 * It is part of package br.org.archimedes.io.xml.parsers on the br.org.archimedes.io.xml project.<br>
 */

import java.text.NumberFormat;
import java.text.ParseException;

import org.w3c.dom.Node;

public class Main {
    private static NumberFormat nf;

    /**
     * Converts a node to a double
     * 
     * @param node
     *            The node to be parsed
     * @return The obtained value
     */
    protected static Double nodeToDouble(Node node) {
        Double returnValue = null;
        try {
            String nodeValue = node.getFirstChild().getNodeValue();
            nodeValue = nodeValue.trim();
            returnValue = nf.parse(nodeValue).doubleValue();
        } catch (ParseException e) {
            // Should never happen
            e.printStackTrace();
        }

        return returnValue;
    }
}

Related

  1. getValue(Node pNode)
  2. getValueByElement(Node node)
  3. getValueByTagName(Node n, String tag)
  4. getValueOfValueNode(Node n)
  5. getValues(Node metric)
  6. putAll(final NamedNodeMap dst, final NamedNodeMap src)
  7. setText(Element parent, String text)
  8. setText(Element parentNode, String data)
  9. setText(Node n, String text)