Java XML Attribute Get getAttrInt(Element root, String attrName)

Here you can find the source of getAttrInt(Element root, String attrName)

Description

Get the value of the specified attribute as an integer.

License

Open Source License

Parameter

Parameter Description
root The element.
attrName The attribute name.

Return

The value of the attribute, if it exists, 0 otherwise.

Declaration

public static int getAttrInt(Element root, String attrName) 

Method Source Code

//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;
    }
}

Related

  1. getAttributeValues(Element el)
  2. getAttributeValues(Node node, String nodeName, String attrName)
  3. getAttributeWithInheritance(Element element, String attributeName)
  4. getAttributName(Node node)
  5. getAttributValue(Node n, String name)
  6. getAttrList(Node node)
  7. getAttrName(String prefix, String name)
  8. getAttrNS(Node node, String nameSpace, String attrName)
  9. getAttrs(Element elem)