Java XML Attribute Get getAttributeMap(NamedNodeMap nodeMap)

Here you can find the source of getAttributeMap(NamedNodeMap nodeMap)

Description

Change NamedNodeMap type to Map type

License

Open Source License

Parameter

Parameter Description
nodeMap NamedNodeMap type

Return

the map

Declaration

public static Map getAttributeMap(NamedNodeMap nodeMap) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  ww w. ja v  a 2 s  .  c  o  m*/
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/

import java.util.HashMap;

import java.util.Map;

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

public class Main {
    /**
     * Change NamedNodeMap type to Map type
     * 
     * @param nodeMap
     *            NamedNodeMap type
     * @return the map
     */
    public static Map getAttributeMap(NamedNodeMap nodeMap) {
        if (nodeMap != null) {
            int len = nodeMap.getLength();
            HashMap map = new HashMap();
            for (int i = 0; i < len; i++) {
                Node node = nodeMap.item(i);
                String name = node.getNodeName();
                String value = node.getNodeValue();
                if (name != null
                        && !name.trim().equalsIgnoreCase("") && value != null) //$NON-NLS-1$
                {
                    map.put(name, value);
                }
            }
            return map;
        }
        return null;
    }
}

Related

  1. getAttributeInteger(String filename, Element parent, String name)
  2. getAttributeInteger(String filename, Element parent, String name)
  3. getAttributeIntValue(Node n, String item, int dflt)
  4. getAttributeList(NamedNodeMap attributeMap)
  5. getAttributeMap(final Node node)
  6. getAttributeMap(XMLEvent evt)
  7. getAttributeMap(XMLStreamReader xmlStreamReader)
  8. getAttributeName(Field field)
  9. getAttributeNames(Element el)