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

ListgetAttributes(final Element element)
Retrieves all Attr Attribute s from a given parent Element as List .
final NamedNodeMap attributes = element.getAttributes();
return new AbstractList<Attr>() {
    @Override
    public Attr get(final int index) {
        return (Attr) attributes.item(index);
    @Override
    public int size() {
...
String[]getAttributes(final Node node, final String[] attributeNames)
get Attributes
final String[] valueList = new String[attributeNames.length];
final NamedNodeMap attMap = node.getAttributes();
Node tmpNode = null;
for (int i = 0; i < attributeNames.length; i++) {
    try {
        tmpNode = attMap.getNamedItem(attributeNames[i]);
        valueList[i] = tmpNode.getNodeValue();
    } catch (Exception e) {
...
MapgetAttributes(Node element)
Fetches the attributes associated with the given node
Map<Object, Object> attr = new HashMap<Object, Object>();
attr.clear();
NamedNodeMap attributes = element.getAttributes();
if (attributes != null) { 
    for (int i = 0; i < attributes.getLength(); i++) {
        Node n = attributes.item(i);
        attr.put(n.getNodeName(), n.getNodeValue());
return attr;
MapgetAttributes(Node n)
get Attributes
if (n == null)
    return null;
NamedNodeMap attributes = n.getAttributes();
if (attributes == null || attributes.getLength() <= 0)
    return null;
Map<String, String> result = new HashMap<>();
for (int i = 0; i < attributes.getLength(); i++) {
    Attr attr = (Attr) attributes.item(i);
...
ListgetAttributes(Node node)
get Attributes
return getNodesOfType(node.getChildNodes(), Node.ATTRIBUTE_NODE);
MapgetAttributes(Node node)
get Attributes
HashMap<String, String> attributes = new HashMap();
NamedNodeMap tNodeMap = node.getAttributes();
if (tNodeMap != null) {
    for (int i = 0; i < tNodeMap.getLength(); i++) {
        Node nd = tNodeMap.item(i);
        String value = nd.getNodeValue();
        if (value != null && value.length() > 0) {
            attributes.put(nd.getNodeName(), value);
...
MapgetAttributes(Node node)
get Attributes
NamedNodeMap attribs = node.getAttributes();
int attribCount = attribs.getLength();
Map<String, Object> map = new LinkedHashMap<>(attribCount);
for (int j = 0; j < attribCount; j++) {
    Node attrib = attribs.item(j);
    map.put(attrib.getNodeName(), attrib.getNodeValue());
return map;
...
HashMapgetAttributes(Node node)
Puts the node attributes (if it has any) into HashMap
String attrName = null;
String attrValue = null;
HashMap<String, String> attributesMap = new HashMap<String, String>();
NamedNodeMap attributes = node.getAttributes();
for (int attrIndex = 0; attributes != null && attrIndex < attributes.getLength(); attrIndex++) {
    attrName = attributes.item(attrIndex).getNodeName();
    attrValue = attributes.item(attrIndex).getNodeValue();
    attributesMap.put(attrName, attrValue);
...
MapgetAttributes(Node node)
get Attributes
NamedNodeMap attributeMap = node.getAttributes();
HashMap<String, String> attributes = new HashMap<String, String>(attributeMap.getLength());
for (int i = 0; i < attributeMap.getLength(); i++) {
    Node attr = attributeMap.item(i);
    if (attr instanceof Attr) {
        attributes.put(((Attr) attr).getName(), ((Attr) attr).getValue());
return attributes;
HashMapgetAttributes(Node node)
Get all attributes as a Map from a node
final HashMap<String, String> result = new HashMap<>();
final NamedNodeMap atts = node.getAttributes();
for (int i = 0; i < atts.getLength(); i++) {
    final Node att = atts.item(i);
    result.put(att.getNodeName(), att.getNodeValue());
return result;