Java XML Attribute Get getAttributes(Node node)

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

Description

get Attributes

License

LGPL

Declaration

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

Method Source Code

//package com.java2s;
/*// w w w . ja va 2 s  . com
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

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

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static Map<String, String> getAttributes(Node node) {
        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);
                }
            }
        }
        return attributes;
    }
}

Related

  1. getAttributes(final Element element)
  2. getAttributes(final Node node, final String[] attributeNames)
  3. getAttributes(Node element)
  4. getAttributes(Node n)
  5. getAttributes(Node node)
  6. getAttributes(Node node)
  7. getAttributes(Node node)
  8. getAttributes(Node node)
  9. getAttributes(Node node)