Java tutorial
//package com.java2s; /** * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2011 GrossCommerce */ import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static int selectIntElement(Element parent, String elementName) { String result = selectStringElement(parent, elementName, "0"); return Integer.valueOf(result); } public static String selectStringElement(Element parent, String elementName, String defaultVal) { Element element = selectSingleElement(parent, elementName); if (element == null) { return defaultVal; } else { return element.getTextContent(); } } public static Element selectSingleElement(Element parent, String elementName) { NodeList list = parent.getElementsByTagName(elementName); if (list.getLength() > 0) { return (Element) list.item(0); } return null; } }