Java XML Attribute Get getAttributeTable(Element element)

Here you can find the source of getAttributeTable(Element element)

Description

get Attribute Table

License

Open Source License

Declaration

protected static Map<String, String> getAttributeTable(Element element) 

Method Source Code

//package com.java2s;
/*// w  w  w  . j av  a 2s  . c o m
 * CDDL HEADER START
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License). You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 * http://www.sun.com/cddl/cddl.html and legal/CDDLv1.0.txt
 * See the License for the specific language governing
 * permission and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at legal/CDDLv1.0.txt.
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 *
 * Copyright 2009 Sun Microsystems Inc. All Rights Reserved
 * CDDL HEADER END
 */

import java.util.Collections;
import java.util.HashMap;

import java.util.Map;

import org.w3c.dom.Attr;

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

public class Main {
    protected static Map<String, String> getAttributeTable(Element element) {
        NamedNodeMap attrs = element.getAttributes();
        if (attrs == null) {
            return Collections.emptyMap();
        }

        int numAttrs = attrs.getLength();
        Map<String, String> attributeTable = new HashMap<String, String>(numAttrs);
        for (int i = 0; i < numAttrs; i++) {
            Node na = attrs.item(i);
            if (na.getNodeType() != Node.ATTRIBUTE_NODE) {
                continue;
            }
            Attr a = (Attr) na;
            attributeTable.put(a.getName(), a.getValue());
        }
        return attributeTable;
    }
}

Related

  1. getAttributesNamesOf(Element element)
  2. getAttributeString(Node node, String name)
  3. getAttributeStringValue(Node htmlForm, String attributeName, String defaultValue)
  4. getAttributeStringValue(String attribute, NamedNodeMap namedNodeMap)
  5. getAttributesValues(final StartElement element)
  6. getAttributeText(final Node node, final String name)
  7. getAttributeTextContent(Node node, String attiribute_name)
  8. getAttributeUri(Element leaf, Element parent, String defaultBaseUri)
  9. getAttributeValue(@Nonnull final Element aElement, @Nonnull final String sAttrName)