Java XML Node Value getNodeValueAsDate(Node node)

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

Description

Gets the node value as date.

License

Open Source License

Parameter

Parameter Description
node Description of the Parameter

Return

The nodeValueAsDate value

Declaration

public final static Date getNodeValueAsDate(Node node) throws DOMException, ParseException 

Method Source Code

//package com.java2s;
/**//from w ww . j  a v  a2s  . com
 * 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.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     *  Gets the node value as date.
     *
     *@param  node                          Description of the Parameter
     *@return                               The nodeValueAsDate value
     *@exception  DOMException              Description of the Exception
     *@exception  ParseException  Description of the Exception
     */
    public final static Date getNodeValueAsDate(Node node) throws DOMException, ParseException {
        if (node == null)
            return null;

        NamedNodeMap attrs = node.getAttributes();
        Node attr = attrs.getNamedItem("DateTimeFormat");

        // Date format
        String format = attr.getNodeValue().trim();
        node = node.getFirstChild();
        if (node != null) {
            String date = node.getNodeValue().trim();
            DateFormat df = new SimpleDateFormat(format);
            return df.parse(date);
        }
        return null;
    }
}

Related

  1. getNodeValue(Node node, String name, String defaultVal, int index)
  2. getNodeValue(Node node, String nodeKey)
  3. getNodeValue(Node nodeXML)
  4. getNodeValue(org.w3c.dom.Node node)
  5. getNodeValue(org.w3c.dom.Node node)
  6. getNodeValueAsLong(Node node)
  7. getNodeValueAsTime(Node node)
  8. getValue(Node node)
  9. getValue(Node node)