Java XML Node Value getNodeValueAsTime(Node node)

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

Description

Gets the node value as time.

License

Open Source License

Parameter

Parameter Description
node Description of the Parameter

Return

The nodeValueAsTime value

Declaration

public final static long getNodeValueAsTime(Node node) throws DOMException 

Method Source Code

//package com.java2s;
/**//w w w.  j ava  2s. c om
 * Copyright (c) 1999-2007, Fiorano Software Technologies Pvt. Ltd. and affiliates.
 * Copyright (c) 2008-2015, Fiorano Software Pte. Ltd. and affiliates.
 *
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Fiorano Software ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * enclosed with this product or entered into with Fiorano.
 */

import org.w3c.dom.*;

public class Main {
    /**
     *  Gets the node value as time.
     *
     *@param  node              Description of the Parameter
     *@return                   The nodeValueAsTime value
     *@exception  DOMException  Description of the Exception
     */
    public final static long getNodeValueAsTime(Node node) throws DOMException {
        if (node == null)
            return -1;

        NamedNodeMap attrs = node.getAttributes();
        Node attr = attrs.getNamedItem("Unit");
        int factor = 1;
        String unit = attr.getNodeValue();
        if (unit.equals("sec")) {
            factor = 1000;
        } else if (unit.equals("min")) {
            factor = 60000;
        } else if (unit.equals("hr")) {
            factor = 3600000;
        } else if (unit.equals("day")) {
            factor = 86400000;
        }

        node = node.getFirstChild();
        if (node != null) {
            String time = node.getNodeValue().trim();
            return Integer.parseInt(time) * factor;
        }
        return -1;
    }
}

Related

  1. getNodeValue(Node nodeXML)
  2. getNodeValue(org.w3c.dom.Node node)
  3. getNodeValue(org.w3c.dom.Node node)
  4. getNodeValueAsDate(Node node)
  5. getNodeValueAsLong(Node node)
  6. getValue(Node node)
  7. getValue(Node node)
  8. getValue(Node node)
  9. getValue(Node node)