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

StringgetAttributeStringValue(Node htmlForm, String attributeName, String defaultValue)
get Attribute String Value
Node item = htmlForm.getAttributes().getNamedItem(attributeName);
return item == null ? defaultValue : item.getNodeValue();
StringgetAttributeStringValue(String attribute, NamedNodeMap namedNodeMap)
get Attribute String Value
Node node = namedNodeMap.getNamedItem(attribute);
if (node != null) {
    return node.getTextContent();
return null;
MapgetAttributesValues(final StartElement element)
get Attributes Values
final Map<String, String> values = new HashMap<>(4);
@SuppressWarnings("unchecked")
final Iterator<Attribute> attributes = element.getAttributes();
while (attributes.hasNext()) {
    final Attribute attr = attributes.next();
    values.put(attr.getName().getLocalPart(), attr.getValue());
return values;
...
MapgetAttributeTable(Element element)
get Attribute Table
NamedNodeMap attrs = element.getAttributes();
if (attrs == null) {
    return Collections.emptyMap();
int numAttrs = attrs.getLength();
Map<String, String> attributeTable = new HashMap<String, String>(numAttrs);
for (int i = 0; i < numAttrs; i++) {
    Node na = attrs.item(i);
...
StringgetAttributeText(final Node node, final String name)
get Attribute Text
NamedNodeMap nnm = node.getAttributes();
if (nnm == null)
    return null;
Node attr = nnm.getNamedItem(name);
if (attr == null)
    return null;
return attr.getNodeValue();
StringgetAttributeTextContent(Node node, String attiribute_name)
get Attribute Text Content
Node attr = node.getAttributes().getNamedItem(attiribute_name);
if (attr != null) {
    return attr.getTextContent();
return "";
StringgetAttributeUri(Element leaf, Element parent, String defaultBaseUri)
Get uri of a leaf element which is an attribute of its parent.
return hasNamespace(leaf) && parent != null ? getSchemaUri(leaf, defaultBaseUri)
        : getSchemaUri(parent, defaultBaseUri) + "." + leaf.getNodeName();
StringgetAttributeValue(@Nonnull final Element aElement, @Nonnull final String sAttrName)
The latest version of XercesJ 2.9 returns an empty string for non existing attributes.
return getAttributeValue(aElement, sAttrName, null);
StringgetAttributeValue(Element e, String key)
This returns the attribute value for the attribute of the input element with the given name and within no namespace.
String value = null;
NamedNodeMap map = e.getAttributes();
Node keyNode = map.getNamedItem(key);
if (keyNode != null) {
    value = keyNode.getNodeValue();
return value;
StringgetAttributeValue(Element e, String name)
Get an attribute value
Node n = e.getAttributes().getNamedItem(name);
return (n != null) ? n.getNodeValue() : null;