Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { static Integer getIntValue(Element ele, String tagName) { String value = getTextValue(ele, tagName); if (isInteger(value)) return Integer.valueOf(value); else return null; } public static String getTextValue(Element ele, String tagName) { String textVal = null; Element el = getChildElement(ele, tagName); if (el != null) textVal = el.getFirstChild().getNodeValue(); return textVal; } /** * Calls getTextValue and returns a int value */ public static boolean isInteger(String string) { try { Integer.valueOf(string); return true; } catch (NumberFormatException e) { return false; } } public static Element getChildElement(Element parent, String childTagName) { Element el = null; NodeList nl = parent.getElementsByTagName(childTagName); if (nl != null && nl.getLength() > 0) { el = (Element) nl.item(0); } return el; } }