Here you can find the source of getAttribute(Node node, String attribName)
public static String getAttribute(Node node, String attribName)
//package com.java2s; /** Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT */ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /**/*from w ww. jav a 2 s . c o m*/ * get the value for an attribute. * Error if the attribute does not exist. */ public static String getAttribute(Node node, String attribName) { String attributeVal = getAttribute(node, attribName, null); assert (attributeVal != null) : "no attribute named '" + attribName + "' for node '" + node.getNodeName() + "' val=" + node.getNodeValue(); return attributeVal; } /** * get the value for an attribute. If not found, defaultValue is used. */ public static String getAttribute(Node node, String attribName, String defaultValue) { NamedNodeMap attribMap = node.getAttributes(); String attributeVal = null; if (attribMap == null) { return null; } for (int i = 0; i < attribMap.getLength(); i++) { Node attr = attribMap.item(i); if (attr.getNodeName().equals(attribName)) attributeVal = attr.getNodeValue(); } if (attributeVal == null) attributeVal = defaultValue; return attributeVal; } }