Java XML Attribute Get getAttribute(Node node, String attr)

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

Description

Gets a named attribute of a Node

License

Open Source License

Parameter

Parameter Description
node The node to search
attr The name of the attribute to get

Declaration

public synchronized static String getAttribute(Node node, String attr) 

Method Source Code


//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**// ww w . j a v a 2 s  .  c  o  m
     *  Gets a named attribute of a Node<p>
     *  @param node The node to search
     *  @param attr The name of the attribute to get
     */
    public synchronized static String getAttribute(Node node, String attr) {
        if (node == null)
            throw new IllegalArgumentException("Node argument cannot be null");
        if (attr == null)
            throw new IllegalArgumentException("Node attribute argument cannot be null");

        NamedNodeMap map = node.getAttributes();
        if (map != null) {
            Node an = map.getNamedItem(attr);
            if (an != null)
                return an.getNodeValue();
        }

        return null;
    }
}

Related

  1. getAttribute(Node n, String attr, String def)
  2. getAttribute(Node n, String name)
  3. getAttribute(Node node, String att_name)
  4. getAttribute(Node node, String attName, boolean domLevel3)
  5. getAttribute(Node node, String attr)
  6. getAttribute(Node node, String attr)
  7. getAttribute(Node node, String attr)
  8. getAttribute(Node node, String attribName)
  9. getAttribute(Node node, String attribute)