Java Utililty Methods XML Attribute Get

List of utility methods to do XML Attribute Get

Description

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

Method

booleangetBooleanAttributeOption(final Element configuration, final String option, boolean defaultValue)
get Boolean Attribute Option
if (configuration == null) {
    return defaultValue;
String value = configuration.getAttribute(option);
return Boolean.valueOf(value).booleanValue();
BooleangetBooleanAttributeOptional(Node node, String attributeName, Boolean valueIfEmpty)
get Boolean Attribute Optional
String string = getStringAttributeOptional(node, attributeName, null);
if (string == null) {
    return valueIfEmpty;
if (VALUE_TRUE.equals(string)) {
    return true;
} else if (VALUE_FALSE.equals(string)) {
    return false;
...
booleangetBooleanAttributeRequired(Node node, String attributeName)
get Boolean Attribute Required
String string = getStringAttributeRequired(node, attributeName);
if (VALUE_TRUE.equals(string)) {
    return true;
} else if (VALUE_FALSE.equals(string)) {
    return false;
throw new Exception("Could not read boolean from value '" + string + "' in attribute '" + attributeName
        + "' in node '" + node.getLocalName() + "'");
...
BooleangetBooleanAttributeValue(Node node, String attribute)
get Boolean Attribute Value
String value = getAttributeValue(node, attribute);
if (value == null)
    return null;
if (value.equals("1"))
    return true;
if (value.equals("true"))
    return true;
return false;
...
StringgetCascadeValue(final Element elem, final String attrName)
Get cascaded attribute value.
Element current = elem;
while (current != null) {
    final Attr attr = current.getAttributeNode(attrName);
    if (attr != null) {
        return attr.getValue();
    final Node parent = current.getParentNode();
    if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
...
ElementgetClosestAncestorWithAttribute(Node node, String ancestorName, String attributeName)
Search upwards through the ancestors of node with name ancestorName, and return the first ancestor for which an attribute named attributeName is present.
for (Node a = getAncestor(node, ancestorName); a != null; a = getAncestor(a, ancestorName)) {
    if (a.getNodeType() == Node.ELEMENT_NODE && ((Element) a).hasAttribute(attributeName)) {
        return (Element) a;
return null;
ElementgetClosestAncestorWithAttribute(Node node, String ancestorName, String attributeName)
Search upwards through the ancestors of node with name ancestorName, and return the first ancestor for which an attribute named attributeName is present.
for (Node a = getAncestor(node, ancestorName); a != null; a = getAncestor(a, ancestorName)) {
    if (a.getNodeType() == Node.ELEMENT_NODE && ((Element) a).hasAttribute(attributeName)) {
        return (Element) a;
return null;
StringgetCurrentLevelAttributeTextValue(Element ele, String attribute)
get Current Level Attribute Text Value
if (ele == null || attribute == null) {
    return null;
} else {
    return ele.getAttribute(attribute);
NodegetDirectAttribute(Node node, String name)
get Direct Attribute
Node attribute = null;
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
    attribute = attributes.getNamedItem(name);
return attribute;
StringgetDivHeadAttr(Element annotU, String attrName)
get Div Head Attr
String a = annotU.getAttribute(attrName);
if (a == null || a.isEmpty())
    return getHeadAttr(annotU, attrName);
return a;