Here you can find the source of getAttr(final Node n, final String attrName)
Parameter | Description |
---|---|
n | A <code>Node</code> which holds the attribute |
attrName | The name of the attribute |
null
if the attribute does not exsist
public static String getAttr(final Node n, final String attrName)
//package com.java2s; /* License as published by the Free Software Foundation; either */ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /**//from w ww.java 2s . c om * Gives the value of a given attribute * * @param n A <code>Node</code> which holds the attribute * @param attrName The name of the attribute * @return The value of the attribute or <code>null</code> if the attribute does not exsist */ public static String getAttr(final Node n, final String attrName) { String value = null; if (n.hasAttributes()) { final NamedNodeMap map = n.getAttributes(); for (int i = 0; i < map.getLength(); i++) { final Node attrNode = map.item(i); if (attrNode.getNodeName().equals(attrName)) { value = attrNode.getNodeValue(); } } } return value; } }