Java XML Attribute Get getAttrvalue(Node item, String name, boolean ignoreNs)

Here you can find the source of getAttrvalue(Node item, String name, boolean ignoreNs)

Description

get Attrvalue

License

Apache License

Declaration

public static String getAttrvalue(Node item, String name, boolean ignoreNs) 

Method Source Code

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

import org.w3c.dom.Attr;

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

public class Main {
    public static String getAttrvalue(Node item, String name, boolean ignoreNs) {
        NamedNodeMap attributes = item.getAttributes();
        int numAttrs = attributes.getLength();
        for (int i = 0; i < numAttrs; i++) {
            Attr attr = (Attr) attributes.item(i);
            String attrName = attr.getNodeName();
            String NSName = attr.getNamespaceURI();
            if (ignoreNs) {
                if ((attrName.indexOf(":" + name) != -1) || (name.equals(attrName)))
                    return attr.getNodeValue();
            } else {
                if (name.equals(attrName)) {
                    return attr.getNodeValue();
                }/*w  ww .  j  a  va  2  s . c om*/
            }
        }
        return null;
    }
}

Related

  1. getAttrs(Element elem)
  2. getAttrsAsString(Node node)
  3. getAttrString(Element elem, String localName)
  4. getAttrVal(final NamedNodeMap nnm, final String name)
  5. getAttrValue(NamedNodeMap attrs, String attrName)
  6. getAttrValue(Node n, String name)
  7. getAttrValuesByName(Element ele, String attributeName)
  8. getBeanclassAttribute(Node node)
  9. getBool(Element el, String attrName, boolean defaultValue)