/** * Reads the text content of an element. The reader should be positioned in * front of a StartElement event, and will be read up to and including the * end element tag. * * @param reader The event stream from which to read the element text. * @param elemName The optional name of the element being read. If this * paramter is non- <code>null</code> then an exception will * be thrown if the element read doesn't have the same name. * @return The text read from the element. * @throws XMLStreamException If an error occurs reading the stream, or if * the read element doesn't match the provided QName. */ public static final String readTextElement(XMLEventReader reader, QName elemName) throws XMLStreamException { if (elemName != null) { requireStartElement(reader, elemName); } // read text String text = reader.getElementText(); // consume the end tag reader.nextEvent(); return text; }