Here you can find the source of getIntAttr(Element elem, String attName)
Parameter | Description |
---|---|
elem | Element |
attName | Attribute name |
public static int getIntAttr(Element elem, String attName)
//package com.java2s; import org.w3c.dom.Element; public class Main { /**// w ww. j ava2 s.c om * Return the value of an integer attribute or the default value * @param elem Element * @param attName Attribute name * @param defVal default value * @return the parsed attribute value or the default value */ public static int getIntAttr(Element elem, String attName, int defVal) { try { String val = elem.getAttribute(attName); if (val != null) { return Integer.parseInt(val); } } catch (NumberFormatException e) { //nothing, just return the default value } return defVal; } /** * Return the value of an integer attribute or zero * @param elem Element * @param attName Attribute name * @return the parsed attribute value or zero */ public static int getIntAttr(Element elem, String attName) { return getIntAttr(elem, attName, 0); } }