Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Get string value for a tag * * @param xmlElement * Root Element of subtree in which required tag is to be * searched * @param key * Required tage name * @return String value */ public static String getStringValueForXMLTag(Element xmlElement, String key) { NodeList nl = xmlElement.getElementsByTagName(key); String output = "nothing"; if (nl.getLength() > 0) { Node node = nl.item(0).getFirstChild(); if (node != null) { output = node.getNodeValue().trim(); return output; } } return output; } }