Java XML Attribute from Node getXMLDate(Element e, String attrName)

Here you can find the source of getXMLDate(Element e, String attrName)

Description

get XML Date

License

Open Source License

Declaration

public static Date getXMLDate(Element e, String attrName) 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.util.Date;

import org.w3c.dom.Element;

public class Main {
    public static Date getXMLDate(Element e, String attrName) {
        String s = e.getAttribute(attrName);
        if (s == null || s.length() == 0)
            return null;
        try {//from ww w  .j  a va  2s .  c  om
            return parseDate(s);
        } catch (Exception exc) {
            return null;
        }
    }

    private static Date parseDate(String d) throws IllegalArgumentException {
        if (!d.startsWith("@"))
            throw new IllegalArgumentException();
        return new Date(Long.parseLong(d.substring(1)));
    }
}

Related

  1. getNonEmptyAttribute(Element element, String namespace, String localName)
  2. getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty)
  3. getStringAttributeRequired(Node node, String attributeName)
  4. getValueForAttribute(Node currentNode, String attributeName)
  5. getXMLDate(Element e, String attrName)
  6. getXMLInt(Element e, String attrName)
  7. getXMLInt(Element e, String attrName)
  8. getXmlNodeAttribute(String attributeName, NodeList nodeList)
  9. getXmlNodeAttributeValue(Node NN, String AttrName)