Java XML Attribute from Node getNodeAttr(String attrName, Node node)

Here you can find the source of getNodeAttr(String attrName, Node node)

Description

get Node Attr

License

Open Source License

Declaration

public static String getNodeAttr(String attrName, Node node) 

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 {
    public static String getNodeAttr(String attrName, Node node) {
        NamedNodeMap attrs = node.getAttributes();
        for (int y = 0; y < attrs.getLength(); y++) {
            Node attr = attrs.item(y);
            if (attr.getNodeName().equalsIgnoreCase(attrName)) {
                return attr.getNodeValue();
            }//from   w w w . j  a v  a2  s  .  c  o  m
        }
        return "";
    }
}

Related

  1. getIntegerAttribute(Node n, String attributeName)
  2. getIntegerAttribute(Node node, String att_name)
  3. getLongAttributeByName(Node node, String name, long defaultValue)
  4. getLowerAttrValue(Node node, String attr)
  5. getNextSiblingElement(Node node, String elemName, String attrName, String attrValue)
  6. getNodeAttr(String attrName, Node node)
  7. getNodeAttr(String tagName, String attrName, NodeList nodes)
  8. getNodeAttribute(Node n, String as)
  9. getNodeAttribute(Node n, String attrName)