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

StringgetAttributeValue(Node sNode, String attribName)
Utility method to fetch the attribute value from the given element node
String value = null;
NamedNodeMap attrs = sNode.getAttributes();
if (attrs != null) {
    Node attr = attrs.getNamedItem(attribName);
    if (attr != null) {
        value = attr.getNodeValue();
return value;
StringgetAttributeValue(NodeList elements, String attributeName)
Return the value of the named attribute from the first Node in the NodeList or null if the NodeList is empty or the attribute is not present.
String result = null;
if (elements != null && elements.getLength() > 0) {
    Node item = elements.item(0);
    NamedNodeMap attributes = item.getAttributes();
    if (attributes != null) {
        Node attr = attributes.getNamedItem(attributeName);
        if (attr != null) {
            result = attr.getNodeValue();
...
StringgetAttributeValue(StartElement element, String namespaceURI, String localPart)
get Attribute Value
QName name = new QName(namespaceURI == null ? XMLConstants.NULL_NS_URI : namespaceURI, localPart);
Attribute attribute = element.getAttributeByName(name);
return attribute == null ? null : attribute.getValue();
StringgetAttributeValue(StartElement startElement, String attributeName)
Gets the value of a given attribute
String value = null;
Attribute idAttr = startElement.getAttributeByName(new QName(attributeName));
if (idAttr != null) {
    value = idAttr.getValue();
return value;
StringgetAttributeValue(String attributeName, Node xmlNode)
get Attribute Value
if (xmlNode == null)
    return null;
if (xmlNode.getAttributes() == null)
    return null;
if (xmlNode.getAttributes().getLength() == 0)
    return null;
Node n = xmlNode.getAttributes().getNamedItem(attributeName);
if (n == null)
...
BooleangetAttributeValueAsBoolean(Attr attribute)
Parses the attribute's value.
if (attribute == null) {
    return null;
String valueStr = attribute.getValue();
if (valueStr.equals("0") || valueStr.equals("false")) {
    return Boolean.FALSE;
} else if (valueStr.equals("1") || valueStr.equals("true")) {
    return Boolean.TRUE;
...
booleangetAttributeValueAsBoolean(Element el, String attrName)
Get the boolean value from the given attribute.
return getAttributeValueAsBoolean(el, new QName(attrName));
DoublegetAttributeValueAsDouble(Node node, String attributeName)
get Attribute Value As Double
return Double.parseDouble(node.getAttributes().getNamedItem(attributeName).getTextContent());
IntegergetAttributeValueAsInteger(Node node, String attributeName, Integer defaultValue)
get Attribute Value As Integer
final Node attributeNode = node.getAttributes().getNamedItem(attributeName);
return attributeNode != null ? Integer.parseInt(attributeNode.getTextContent()) : defaultValue;
longgetAttributeValueAsLong(final Element el, final String attrName, final long defaultVal)
get Attribute Value As Long
return getAttributeValueAsLong(el, new QName(attrName), defaultVal);