Java XML Attribute Get getAttributes(Node node)

Here you can find the source of getAttributes(Node node)

Description

Creates a map from the attributes of a Node

License

Open Source License

Parameter

Parameter Description
node Node to get attributes from

Return

Map of attributes to values

Declaration

public static Map<String, String> getAttributes(Node node) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Attr;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import java.util.*;

public class Main {
    /**/*w w w  . j  a va2  s .  c o  m*/
     * Creates a map from the attributes of a Node
     *
     * @param node Node to get attributes from
     * @return Map of attributes to values
     */
    public static Map<String, String> getAttributes(Node node) {
        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;
    }
}

Related

  1. getAttributes(Node node)
  2. getAttributes(Node node)
  3. getAttributes(Node node)
  4. getAttributes(Node node)
  5. getAttributes(Node node)
  6. getAttributes(String element, String xsd)
  7. getAttributes(XMLEvent evt)
  8. getAttributesAsMap(Element e)
  9. getAttributesByName(Node node, ArrayList attrNames)