Java Utililty Methods XML Attribute Set

List of utility methods to do XML Attribute Set

Description

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

Method

Stringattr(Element element, String name)
Get an attribute value if it exists, or null
return attr(element, name, true);
Stringattr(Element element, String name)
Get an attribute value if it exists, or null
if (element.hasAttribute(name)) {
    return element.getAttribute(name);
return null;
MapattrbiuteToMap(NamedNodeMap attributes)
attrbiute To Map
if (attributes == null)
    return new LinkedHashMap<String, String>();
Map<String, String> result = new LinkedHashMap<String, String>();
for (int i = 0; i < attributes.getLength(); i++) {
    result.put(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue());
return result;
Stringattribute(Element element, String attrName)
attribute
Attr attr = element.getAttributeNode(attrName);
return attr != null ? attr.getValue() : null;
Stringattribute(Node node, String... attributes)
attribute
String value = attributeOrNull(node, attributes);
return value == null ? "" : value;
booleanattributeBooleanGet(Element e, String name, boolean defaultValue)
attribute Boolean Get
if (!e.hasAttribute(name)) {
    return defaultValue;
} else {
    return Boolean.parseBoolean(e.getAttribute(name));
voidattributeBooleanSet(Element base, String name, boolean value, boolean defaultValue)
Sets an attribute on the specified element with the specified name if the specified value is different from the specified default value.
if (value != defaultValue) {
    base.setAttribute(name, Boolean.toString(value));
booleanattributeBoolValue(Element e, String attr)
attribute Bool Value
if (!e.hasAttribute(attr))
    return false;
String val = e.getAttribute(attr);
return val.equals("yes") || val.equals("true") || val.equals("1");
floatattributeFloat(Node node, String attributeName)
attribute Float
return Float.parseFloat(attributeString(node, attributeName));
intattributeIntValue(Element e, String attr)
attribute Int Value
return attributeIntValue(e, attr, null);