How do I get xml attribute as an integer value?

In this example you can see how we can read xml attribute value as an integer value instead of string. JDOM provides method such as getIntValue(), getLongValue(), getFloatValue(), getDoubleValue() to get numerical values. For boolean value we can use the getBooleanValue() method.

package org.kodejava.example.jdom;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;


public class JDOMIntegerAttributeValue {
    public static void main(String[] args) {
        String xml = "<root><table width=\"100\"/></root>";

        SAXBuilder builder = new SAXBuilder();
        try {
            Document document = StringReader(xml));

            Element child = document.getRootElement().getChild("table");
            int tableWidth = child.getAttribute("width").getIntValue();
            System.out.println("tableWidth = " + tableWidth);
        } catch (JDOMException e) {
        } catch (IOException e) {