Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static String getFirstElementText(Document parent, String tag) { NodeList nl = parent.getElementsByTagName(tag); if (nl.getLength() > 0) { return ((Element) nl.item(0)).getTextContent(); } return null; } public static String getFirstElementText(Element parent, String tag) { NodeList nl = parent.getElementsByTagName(tag); if (nl.getLength() > 0) { return ((Element) nl.item(0)).getTextContent(); } return null; } }