Java XML Attribute Get getAttributeValue(Node n, String name)

Here you can find the source of getAttributeValue(Node n, String name)

Description

Lookup an attribute from a DOM node.

License

Open Source License

Parameter

Parameter Description
n a parameter
name a parameter

Declaration

public static String getAttributeValue(Node n, String name) 

Method Source Code


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

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

public class Main {
    /**/*  w w w  .  jav  a 2  s.  c  o m*/
     * Lookup an attribute from a DOM node.
     * @param n
     * @param name
     * @return
     */
    public static String getAttributeValue(Node n, String name) {
        NamedNodeMap nm = n.getAttributes();

        for (int i = 0; i < nm.getLength(); i++) {
            Node node = nm.item(i);

            if (name.equals(node.getNodeName())) {
                return node.getNodeValue();
            }
        }

        return "";
    }
}

Related

  1. getAttributeValue(NamedNodeMap attributes, String name)
  2. getAttributeValue(Node element, String attribute)
  3. getAttributeValue(Node element, String attribute)
  4. getAttributeValue(Node htmlForm, String attributeName)
  5. getAttributeValue(Node iNode, String iAttributeName)
  6. getAttributeValue(Node n, String name)
  7. getAttributeValue(Node n, String nodePath, String attrName)
  8. getAttributeValue(Node node, String attName)
  9. getAttributeValue(Node node, String attName)