Java Utililty Methods XML Attribute from Element

List of utility methods to do XML Attribute from Element

Description

The list of methods to do XML Attribute from Element are organized into topic(s).

Method

intgetIntAttribute(Element element, String name, int defaultValue)
Get the value of an attribute of the given element with the given name as an integer, or return the given default value if the attribute is missing or not parseable as an integer.
String s = element.getAttribute(name);
if (s != null) {
    try {
        return Integer.parseInt(s);
    } catch (NumberFormatException e) {
return defaultValue;
...
IntegergetIntAttribute(NamedNodeMap namedNodeMap, String name)
get Int Attribute
String value = getAttribute(namedNodeMap, name);
if (value == null) {
    return null;
} else {
    return Integer.valueOf(value);
intgetIntAttributeIgnoreCase(Element ele, String attr, int defaultvalue)
get Int Attribute Ignore Case
if (ele == null) {
    return defaultvalue;
String attrvalue = getAttributeIgnoreCase(ele, attr);
if (attrvalue == null) {
    return defaultvalue;
try {
...
intgetIntAttributeValue(Element element, String attribute)
get Int Attribute Value
int ret;
Attr attr = element.getAttributeNode(attribute);
try {
    ret = Integer.valueOf(attr.getValue());
} catch (NumberFormatException e) {
    ret = 0;
return ret;
...
intgetInteger(final org.w3c.dom.Element element, final String attr, int def)
Returns the integer value of the given XML attribute; or the default value.
if (element.getAttributeNode(attr) == null)
    return def;
try {
    return Integer.parseInt(element.getAttribute(attr).trim());
} catch (NumberFormatException e) {
    return def;
intgetIntegerAttribute(Element el, String attribute)
get Integer Attribute
String attributeValue = el.getAttribute(attribute);
try {
    return Integer.parseInt(attributeValue);
} catch (NumberFormatException e) {
    return -1;
intgetIntegerAttribute(Element element, String name)
get Integer Attribute
return Integer.parseInt(getAttribute(element, name));
StringgetStringAttr(Element element, String name, String def)
get String Attr
String attr = element.getAttribute(name);
if (attr.isEmpty()) {
    attr = def;
return attr;
StringgetStringAttribute(Element e, String name, String def)
get String Attribute
String r = e.getAttribute(name);
if (r == null || "".equals(r.trim()))
    r = def;
return r;
StringgetStringAttribute(Element el, String attribute)
get String Attribute
return el.getAttribute(attribute);