Java XML Attribute Get getAttr(NamedNodeMap attrs, String name)

Here you can find the source of getAttr(NamedNodeMap attrs, String name)

Description

get Attr

License

Apache License

Declaration

public static String getAttr(NamedNodeMap attrs, String name) 

Method Source Code

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

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

public class Main {
    public static String getAttr(NamedNodeMap attrs, String name) {
        return getAttr(attrs, name, null);
    }/*  ww  w.j  a  va  2  s. com*/

    public static String getAttr(Node nd, String name) {
        return getAttr(nd.getAttributes(), name);
    }

    public static String getAttr(NamedNodeMap attrs, String name, String missing_err) {
        Node attr = attrs == null ? null : attrs.getNamedItem(name);
        if (attr == null) {
            if (missing_err == null)
                return null;
            throw new RuntimeException(missing_err + ": missing mandatory attribute '" + name + "'");
        }
        String val = attr.getNodeValue();
        return val;
    }

    public static String getAttr(Node node, String name, String missing_err) {
        return getAttr(node.getAttributes(), name, missing_err);
    }
}

Related

  1. getAtrributeValue(Node node, String attribute)
  2. getAttr(Element e, String name)
  3. getAttr(Element elem, String name)
  4. getAttr(final Node n, final String attr)
  5. getAttr(final Node n, final String attrName)
  6. getAttr(NamedNodeMap attrs, String name, String missing_err)
  7. getAttr(Node n, String name)
  8. getAttr(Node node, String attr)
  9. getAttr(Node node, String name)