Java XML Attribute Get getAttributes(Node n)

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

Description

get Attributes

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/* Copyright (c) 2016 by crossmobile.org
 *
 * CrossMobile 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, version 2.
 *
 * CrossMobile 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 CrossMobile; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *//*from   w  w w  .j a va 2 s  .  c o  m*/

import java.util.HashMap;

import java.util.Map;

import org.w3c.dom.Attr;

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

public class Main {
    public static Map<String, String> getAttributes(Node n) {
        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);
            result.put(attr.getNodeName(), attr.getNodeValue());
        }
        return result;
    }
}

Related

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