Java XML Attribute Get getAttributes(Node node)

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

Description

get Attributes

License

Open Source License

Declaration

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

Method Source Code

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

import java.util.HashMap;

import java.util.Map;

import javax.xml.namespace.QName;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.Node;

import org.w3c.dom.Attr;

public class Main {
    static public Map<QName, String> getAttributes(Node node) {
        Map<QName, String> atts = new HashMap<QName, String>();
        NamedNodeMap nnm = node.getAttributes();
        if (nnm != null) {
            for (int i = 0; i < nnm.getLength(); i++) {
                Attr att = (Attr) nnm.item(i);
                String uri = att.getBaseURI();
                String localname = att.getLocalName();
                String prefix = att.getPrefix();
                QName name;/*from  w ww  .j  a v  a 2  s .c  o m*/
                if (uri == null) {
                    name = new QName(localname);
                } else if (prefix == null) {
                    name = new QName(uri, localname);
                } else {
                    name = new QName(uri, localname, prefix);
                }
                if (prefix == null || !(prefix.equals("xmlns") || prefix.equals("xml"))) {
                    atts.put(name, att.getValue());
                }
            }
        }
        return atts;
    }
}

Related

  1. getAttributes(Node node)
  2. getAttributes(Node node)
  3. getAttributes(Node node)
  4. getAttributes(Node node)
  5. getAttributes(Node node)
  6. getAttributes(Node node)
  7. getAttributes(Node node)
  8. getAttributes(String element, String xsd)
  9. getAttributes(XMLEvent evt)