Java XML Attribute Get getAttributesNamesOf(Element element)

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

Description

Gets the names of all the attributes of the given Element .

License

Open Source License

Parameter

Parameter Description
element The Element to get the attribute names of.

Return

Returns an array, possibly empty, of the attribute names.

Declaration

public static String[] getAttributesNamesOf(Element element) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.*;

public class Main {
    /**//from w  w  w. j  a v  a  2 s. c o m
     * Gets the names of all the attributes of the given {@link Element}.
     *
     * @param element The {@link Element} to get the attribute names of.
     * @return Returns an array, possibly empty, of the attribute names.
     */
    public static String[] getAttributesNamesOf(Element element) {
        final NamedNodeMap map = element.getAttributes();
        final int numAttributes = map.getLength();
        final String[] result = new String[numAttributes];
        for (int i = 0; i < numAttributes; ++i)
            result[i] = map.item(i).getNodeName();
        return result;
    }
}

Related

  1. getAttributes(String element, String xsd)
  2. getAttributes(XMLEvent evt)
  3. getAttributesAsMap(Element e)
  4. getAttributesByName(Node node, ArrayList attrNames)
  5. getAttributesCompact(NamedNodeMap attributes)
  6. getAttributeString(Node node, String name)
  7. getAttributeStringValue(Node htmlForm, String attributeName, String defaultValue)
  8. getAttributeStringValue(String attribute, NamedNodeMap namedNodeMap)
  9. getAttributesValues(final StartElement element)