Java XML Attribute Read getLongAttribute(String name, Element el)

Here you can find the source of getLongAttribute(String name, Element el)

Description

Gets the value of the DOM element's attribute with the given name as a Long, or null if the value is not a long.

License

Open Source License

Declaration

public static Long getLongAttribute(String name, Element el) 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /**/*from w w  w  . j  a  v  a2  s.c om*/
     * Gets the value of the DOM element's attribute with the given name
     * as a Long, or null if the value is not a long.
     */
    public static Long getLongAttribute(String name, Element el) {
        return stringToLong(getAttribute(name, el));
    }

    private static Long stringToLong(String value) {
        if (value == null)
            return null;
        try {
            return new Long(value);
        } catch (NumberFormatException exc) {
            return null;
        }
    }

    /**
     * Gets the value of the given DOM element's attribute
     * with the specified name.
     */
    public static String getAttribute(String name, Element el) {
        if (name == null || el == null)
            return null;
        if (!el.hasAttribute(name))
            return null;
        return el.getAttribute(name);
    }
}

Related

  1. getLong(Node xmlNode, String attributeLabel)
  2. getLong(String attrName, Map runtimeAttributes, Node docElement)
  3. getLongAttribute(NamedNodeMap namedNodeMap, String name)
  4. getNameAttribute(final Node aNode)
  5. getNamedAttribute(final Node aNode, final String attributeName)
  6. getNewAttribute(Element element, String name)
  7. getNSPrefixFromNSAttr(Attr a)