Here you can find the source of getElementContents(Element element, String elementName)
public static String getElementContents(Element element, String elementName) throws IOException
//package com.java2s; /*//from w w w. j a v a 2s. co m * XmlUtil.java * * (c) 2009 The Echo Nest * See "license.txt" for terms * * */ import java.io.IOException; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static String getElementContents(Element element, String elementName) throws IOException { Element first = getFirstElement(element, elementName); if (first != null) { return first.getTextContent().trim(); } else { return null; } } public static Element getFirstElement(Element element, String elementName) throws IOException { NodeList list = element.getElementsByTagName(elementName); if (list.getLength() >= 1) { Element subElement = (Element) list.item(0); return subElement; } else { return null; } } }