Here you can find the source of getAttribute(Node n, String attr, String def)
Parameter | Description |
---|---|
n | Node to examine |
attr | Attribute to look for |
def | Default value to return if attribute is not present |
public static String getAttribute(Node n, String attr, String def)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /**/*from w ww. j a va2 s. co m*/ * @param n Node to examine * @param attr Attribute to look for * @param def Default value to return if attribute is not present * @return if the Node contains the named Attribute, the value, if not, the def parameter */ public static String getAttribute(Node n, String attr, String def) { NamedNodeMap attrs = n.getAttributes(); if (attrs == null) return def; Node ret = attrs.getNamedItem(attr); if (ret == null) return def; else return ret.getNodeValue(); } /** * @param n Node to examine * @param attr Attribute to look for * @return if the Node contains the named Attribute, the value, if not, empty string */ public static String getAttribute(Node n, String attr) { return getAttribute(n, attr, ""); } }