Java XML Attribute Load getAllAttributesAsMap(@Nullable final Element aSrcNode)

Here you can find the source of getAllAttributesAsMap(@Nullable final Element aSrcNode)

Description

get All Attributes As Map

License

Apache License

Declaration

@Nullable
    public static Map<String, String> getAllAttributesAsMap(@Nullable final Element aSrcNode) 

Method Source Code

//package com.java2s;
/**//from   w  w w  .  j a  v  a2 s  .  c  o m
 * Copyright (C) 2014-2015 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nonnegative;

import javax.annotation.Nullable;

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.NodeList;

public class Main {
    @Nullable
    public static Map<String, String> getAllAttributesAsMap(@Nullable final Element aSrcNode) {
        if (aSrcNode != null) {
            final NamedNodeMap aNNM = aSrcNode.getAttributes();
            if (aNNM != null) {
                final Map<String, String> aMap = new LinkedHashMap<String, String>(aNNM.getLength());
                final int nMax = aNNM.getLength();
                for (int i = 0; i < nMax; ++i) {
                    final Attr aAttr = (Attr) aNNM.item(i);
                    aMap.put(aAttr.getName(), aAttr.getValue());
                }
                return aMap;
            }
        }
        return null;
    }

    @Nonnegative
    public static int getLength(@Nullable final NodeList aNL) {
        return aNL == null ? 0 : aNL.getLength();
    }
}

Related

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