Java XML Attribute Get getAttributeInteger(String filename, Element parent, String name)

Here you can find the source of getAttributeInteger(String filename, Element parent, String name)

Description

Gets the attribute integer.

License

Open Source License

Parameter

Parameter Description
filename the filename
parent the parent
name the name

Exception

Parameter Description
Exception the exception

Return

the attribute integer

Declaration

public static Integer getAttributeInteger(String filename, Element parent, String name) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

import org.w3c.dom.Element;

public class Main {
    /**/* w ww  .  j  av a  2s  .  c  o  m*/
     * Gets the attribute integer.
     *
     * @param filename the filename
     * @param parent the parent
     * @param name the name
     * @return the attribute integer
     * @throws Exception the exception
     */
    public static Integer getAttributeInteger(String filename, Element parent, String name) throws Exception {
        String attrStr = parent.getAttribute(name);
        if (attrStr == null) {
            return null;
        }
        return textToInteger(filename, attrStr, name);
    }

    private static Integer textToInteger(String filename, String text, String name) throws Exception {
        if (text == null || text.length() == 0) {
            throw new Exception("Bad integer. Filename= " + filename + ", name= " + name);
        }
        Integer intValue = null;
        try {
            intValue = Integer.valueOf(text);
        } catch (NumberFormatException e) {
            throw new Exception("Bad integer. Filename= " + filename + ", exception= " + e.toString());
        }
        return intValue;
    }
}

Related

  1. getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName)
  2. getAttributeIfExists(Node node, String name)
  3. getAttributeIgnoreCase(Element element, String attributeName)
  4. getAttributeIgnoreCase(Element element, String string)
  5. getAttributeIntArray(final Node node, final String attribname)
  6. getAttributeInteger(String filename, Element parent, String name)
  7. getAttributeIntValue(Node n, String item, int dflt)
  8. getAttributeList(NamedNodeMap attributeMap)
  9. getAttributeMap(final Node node)