Here you can find the source of getIntAttributeRequired(Node node, String attributeName)
public static int getIntAttributeRequired(Node node, String attributeName) throws Exception
//package com.java2s; //License from project: Apache License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static int getIntAttributeRequired(Node node, String attributeName) throws Exception { String string = getStringAttributeRequired(node, attributeName); try {/*w ww .j a v a2 s.c o m*/ return Integer.parseInt(string); } catch (Exception e) { throw new Exception("Could not read integer from value '" + string + "' in attribute '" + attributeName + "' in node '" + node.getLocalName() + "'"); } } public static String getStringAttributeRequired(Node node, String attributeName) throws Exception { NamedNodeMap attributes = node.getAttributes(); Node value = attributes.getNamedItem(attributeName); if (value == null) { throw new Exception("Missing attribute '" + attributeName + "' in node '" + node.getNodeName() + "'"); } String text = value.getTextContent(); if (text == null) { throw new Exception("Missing text '" + attributeName + "' in node '" + node.getNodeName() + "'"); } return text; } }