Here you can find the source of getAttrInt(Element root, String attrName)
Parameter | Description |
---|---|
root | The element. |
attrName | The attribute name. |
public static int getAttrInt(Element root, String attrName)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w .ja va2s. c o m*/ * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ import org.w3c.dom.*; public class Main { /** * Get the value of the specified attribute as an integer. If the element has no attribute by the specified name, 0 * is returned. * * @param root The element. * @param attrName The attribute name. * @return The value of the attribute, if it exists, 0 otherwise. */ public static int getAttrInt(Element root, String attrName) { if (root.hasAttribute(attrName)) return Integer.valueOf(root.getAttribute(attrName)).intValue(); return 0; } }