Java XML Attribute Get getAttributeNames(Element el)

Here you can find the source of getAttributeNames(Element el)

Description

Gets a list of all attribute names for the given DOM element.

License

Open Source License

Declaration

public static String[] getAttributeNames(Element el) 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /** Gets a list of all attribute names for the given DOM element. */
    public static String[] getAttributeNames(Element el) {
        NamedNodeMap map = el.getAttributes();
        int len = map.getLength();
        String[] attrNames = new String[len];
        for (int i = 0; i < len; i++) {
            Attr attr = (Attr) map.item(i);
            attrNames[i] = attr == null ? null : attr.getName();
        }/*from   www.j av a  2s .c om*/
        return attrNames;
    }

    /** Gets the local (sans namespace) name of the given node. */
    public static String getName(Node node) {
        // NB: The node.getLocalName() method does not work.
        String name = node.getNodeName();
        int colon = name.lastIndexOf(":");
        return colon < 0 ? name : name.substring(colon + 1);
    }
}

Related

  1. getAttributeMap(final Node node)
  2. getAttributeMap(NamedNodeMap nodeMap)
  3. getAttributeMap(XMLEvent evt)
  4. getAttributeMap(XMLStreamReader xmlStreamReader)
  5. getAttributeName(Field field)
  6. getAttributeNames(Element element)
  7. getAttributeNames(final Element e)
  8. getAttributeNode(Node sNode, String attribName)
  9. getAttributeNode(Node sNode, String attribName)