Here you can find the source of getIntAttribute(Element element, String name, int defaultValue)
Parameter | Description |
---|---|
element | the element in which to find the attribute |
name | the name of the attribute |
defaultValue | the value to return if the attribute value is not parseable as an integer |
public static int getIntAttribute(Element element, String name, int defaultValue)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2011 The University of Memphis. All rights reserved. * This program and the accompanying materials are made available * under the terms of the LIDA Software Framework Non-Commercial License v1.0 * which accompanies this distribution, and is available at * http://ccrg.cs.memphis.edu/assets/papers/2010/LIDA-framework-non-commercial-v1.0.pdf *******************************************************************************/ import org.w3c.dom.Element; public class Main { /**/*w w w .j a v a 2s .co m*/ * Get the value of an attribute of the given element with the given name as * an integer, or return the given default value if the attribute is missing * or not parseable as an integer. * * @param element * the element in which to find the attribute * @param name * the name of the attribute * @param defaultValue * the value to return if the attribute value is not parseable as * an integer * @return the integer value of the attribute, or the default value */ public static int getIntAttribute(Element element, String name, int defaultValue) { String s = element.getAttribute(name); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException e) { // ignore } } return defaultValue; } }