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

BSD License

Parameter

Parameter Description
n a parameter
name a parameter

Declaration

private static String getAttributeValue(Node n, String name) 

Method Source Code

//package com.java2s;
/**/*from   w  ww.  j ava 2s.  co  m*/
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

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

public class Main {
    /**
     * Lookup an attribute from a DOM node.
     * @param n
     * @param name
     * @return
     */
    private 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(Node element, String attribute)
  2. getAttributeValue(Node element, String attribute)
  3. getAttributeValue(Node htmlForm, String attributeName)
  4. getAttributeValue(Node iNode, String iAttributeName)
  5. getAttributeValue(Node n, String name)
  6. getAttributeValue(Node n, String nodePath, String attrName)
  7. getAttributeValue(Node node, String attName)
  8. getAttributeValue(Node node, String attName)
  9. getAttributeValue(Node node, String attribute)