Java XML Attribute Get getAttributes(final Element element)

Here you can find the source of getAttributes(final Element element)

Description

Retrieves all Attr Attribute s from a given parent Element as List .

License

Apache License

Parameter

Parameter Description
element the parent Element

Return

the of Attribute s

Declaration

public static List<Attr> getAttributes(final Element element) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.AbstractList;

import java.util.List;

import org.w3c.dom.Attr;

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

public class Main {
    /**/*from  www  .j av a  2 s .co m*/
     * Retrieves all {@link Attr Attribute}s from a given parent {@link Element}
     * as {@link List}.
     * 
     * @param element
     *           the parent {@link Element}
     * @return the {@link List} of {@link Attr Attribute}s
     */
    public static List<Attr> getAttributes(final Element element) {
        final NamedNodeMap attributes = element.getAttributes();

        return new AbstractList<Attr>() {
            @Override
            public Attr get(final int index) {
                return (Attr) attributes.item(index);
            }

            @Override
            public int size() {
                return attributes.getLength();
            }
        };
    }
}

Related

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