Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class Main { /** * Returns the inner value of the named node in the given document. The node must only exist once * * @param doc the XML document * @param nodeName the name of the node * @return the value of the named node */ public static String getNodeInnerValue(final Document doc, final String nodeName) throws SAXException { final NodeList nodes = doc.getElementsByTagName(nodeName); if (nodes.getLength() != 1) { throw new SAXException("Could not get single node for " + nodeName); } final NodeList childNodes = nodes.item(0).getChildNodes(); if (childNodes.getLength() != 1) { throw new SAXException("Could not get single child node for " + nodeName); } return childNodes.item(0).getNodeValue(); } }