Here you can find the source of getElementValue(Element root, String name)
public static String getElementValue(Element root, String name) throws Exception
//package com.java2s; /*/*from www. ja v a 2 s .c om*/ * $File$ $Revision$ $Date$ * * ADOBE SYSTEMS INCORPORATED * Copyright 2007 Adobe Systems Incorporated * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the * terms of the Adobe license agreement accompanying it. If you have received this file from a * source other than Adobe, then your use, modification, or distribution of it requires the prior * written permission of Adobe. */ import javax.xml.parsers.*; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Element; import org.w3c.dom.ls.DOMImplementationLS; public class Main { public static boolean DEBUG = false; public static String getElementValue(Element root, String name) throws Exception { try { return root.getElementsByTagName(name).item(0).getTextContent(); } catch (Exception e) { if (DEBUG) { System.out.println("element: " + name); System.out.println(printXML(root)); } throw e; } } public static String printXML(Element root) throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); DOMImplementationLS ls = (DOMImplementationLS) impl.getFeature( "LS", "3.0"); return ls.createLSSerializer().writeToString(root); } }