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   www . java2 s .  c  o m
            return parseDate(s);
        } catch (Exception exc) {
            return null;
        }
    }

    public static String getAttribute(Element e, String attrName, String def) {
        String result = e.getAttribute(attrName);
        if (!hasValue(result))
            result = def;
        return result;
    }

    public static Date parseDate(String d) throws IllegalArgumentException {
        if (d == null || d.length() == 0)
            return null;
        if (!d.startsWith("@"))
            throw new IllegalArgumentException();
        return new Date(Long.parseLong(d.substring(1)));
    }

    public static boolean hasValue(String val) {
        return (val != null && val.length() > 0);
    }
}

Related

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