Java XML Attribute Load getAllAttributes(Node node)

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

Description

Returns a map of all node's attributes.

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/**/*from www.j a  v  a  2  s .  com*/
 * This file is part of SIMPL4(http://simpl4.org).
 *
 *    Copyright [2014] [Manfred Sattler] <manfred@ms123.org>
 *
 * SIMPL4 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SIMPL4 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SIMPL4.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.HashMap;

import java.util.Map;

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

public class Main {
    /**
     * Returns a map of all node's attributes. All non-attribute nodes are ignored.
     */
    public static Map<String, String> getAllAttributes(Node node) {
        HashMap<String, String> attrs = new HashMap<String, String>();
        NamedNodeMap nmm = node.getAttributes();
        for (int j = 0; j < nmm.getLength(); j++) {
            Node attribute = nmm.item(j);
            if (attribute.getNodeType() != Node.ATTRIBUTE_NODE) {
                continue;
            }
            attrs.put(attribute.getNodeName(), attribute.getNodeValue());
        }
        return attrs;
    }
}

Related

  1. getAllAttributes(Element e)
  2. getAllAttributes(Element elem, String name)
  3. getAllAttributes(Element element)
  4. getAllAttributes(Node node)
  5. getAllAttributesAsMap(@Nullable final Element aSrcNode)
  6. getAllAttrs(Element parent, String name, List lst)
  7. getAllAttrValueByName(Node item, String name)
  8. getAllElementAttributes(Element element)