Java XML Attribute Get getAttribute(final Node node, final String name)

Here you can find the source of getAttribute(final Node node, final String name)

Description

get Attribute

License

Apache License

Declaration

public static final Node getAttribute(final Node node, final String name) 

Method Source Code

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

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

public class Main {
    public static final Node getAttribute(final Node node, final String name) {
        if (node == null) {
            throw new IllegalArgumentException("The node is null.");
        } else if (name == null || name.isEmpty()) {
            throw new IllegalArgumentException("The attribute's name is null or empty.");
        } else {//from w  w  w .  j  a  v a  2s  .  com
            final NamedNodeMap namedNodeMap = node.getAttributes();
            if (namedNodeMap != null) {
                return namedNodeMap.getNamedItem(name);
            }
        }
        return null;
    }
}

Related

  1. getAttribute(final List elements, final int index)
  2. getAttribute(final Node iNode, final String iAttributeName)
  3. getAttribute(final Node n, final String attrName, final String defaultValue)
  4. getAttribute(final Node node, final String attribname, final int def)
  5. getAttribute(final Node node, final String attributeName)
  6. getAttribute(final Node xml, final String namespaceURI, final String localName)
  7. getAttribute(NamedNodeMap map, String name)
  8. getAttribute(NamedNodeMap namedNodeMap, String name)
  9. getAttribute(NamedNodeMap ruleAttributes, String attributeName)