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

String[]getAttributeNames(Element el)
Gets a list of all attribute names for the given DOM element.
NamedNodeMap map = el.getAttributes();
int len = map.getLength();
String[] attrNames = new String[len];
for (int i = 0; i < len; i++) {
    Attr attr = (Attr) map.item(i);
    attrNames[i] = attr == null ? null : attr.getName();
return attrNames;
...
ListgetAttributeNames(Element element)
get Attribute Names
List<String> names = new ArrayList<String>();
NamedNodeMap list = element.getAttributes();
for (int i = 0; i < list.getLength(); i++) {
    names.add(list.item(i).getNodeName());
return names;
ListgetAttributeNames(final Element e)
Get a list of the attribute names of an element.
if (e == null) {
    return null;
final List<String> result = new ArrayList<>();
final NamedNodeMap map = e.getAttributes();
for (int i = 0; i < map.getLength(); i++) {
    final Node attribute = map.item(i);
    result.add(attribute.getNodeName());
...
NodegetAttributeNode(Node sNode, String attribName)
Decide if the node is text, and so must be handled specially
NamedNodeMap attrs = sNode.getAttributes();
if (attrs != null) {
    return attrs.getNamedItem(attribName);
return null;
NodegetAttributeNode(Node sNode, String attribName)
get Attribute Node
NamedNodeMap attrs = sNode.getAttributes();
if (attrs != null) {
    return attrs.getNamedItem(attribName);
return null;
ListgetAttributeNodeList(Element element, Pattern name)
get Attribute Node List
NamedNodeMap nodes = element.getAttributes();
List<Node> attributes = new ArrayList<>();
int i, size = nodes.getLength();
Node node;
for (i = 0; i < size; i++) {
    node = nodes.item(i);
    if (name.matcher(node.getNodeName()).find())
        attributes.add(node);
...
StringgetAttributeNS(Element el, String namespaceURI, String localPart)
Returns the value of an attribute of an element.
String sRet = null;
Attr attr = el.getAttributeNodeNS(namespaceURI, localPart);
if (attr != null) {
    sRet = attr.getValue();
return sRet;
StringgetAttributeNS(Element elem, String namespace, String att)
get Attribute NS
String res = elem.getAttributeNS(namespace, att);
return res.length() == 0 && !elem.hasAttributeNS(namespace, att) ? null : res;
QNamegetAttributeNSName(Element e, String attrName)
get Attribute NS Name
String attrValue = e.getAttribute(attrName);
return getNSName(e, attrValue);
StringgetAttributeNSOrNull(Element e, String name, String nsURI)
get Attribute NS Or Null
Attr a = e.getAttributeNodeNS(nsURI, name);
if (a == null)
    return null;
return a.getValue();