Java XML Attribute from Element getIntegerAttribute(Element element, String name)

Here you can find the source of getIntegerAttribute(Element element, String name)

Description

get Integer Attribute

License

Open Source License

Declaration

public static int getIntegerAttribute(Element element, String name) 

Method Source Code


//package com.java2s;
/*//from   w w w . j av a2s  . c o m
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

import java.util.NoSuchElementException;
import org.w3c.dom.*;

public class Main {
    public static int getIntegerAttribute(Element element, String name) {
        return Integer.parseInt(getAttribute(element, name));
    }

    public static String getAttribute(Element element, String name) {
        String value = element.getAttribute(name);
        if (value != null && !value.isEmpty()) {
            return value;
        }
        throw new NoSuchElementException(String.format("Element <%s> has no \"%s\" attribute", element, name));
    }
}

Related

  1. getIntAttribute(NamedNodeMap namedNodeMap, String name)
  2. getIntAttributeIgnoreCase(Element ele, String attr, int defaultvalue)
  3. getIntAttributeValue(Element element, String attribute)
  4. getInteger(final org.w3c.dom.Element element, final String attr, int def)
  5. getIntegerAttribute(Element el, String attribute)
  6. getStringAttr(Element element, String name, String def)
  7. getStringAttribute(Element e, String name, String def)
  8. getStringAttribute(Element el, String attribute)
  9. getStringAttributeValue(Element element, String attribute)