Java tutorial
//package com.java2s; //License from project: Apache License import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class Main { /** * Load text of the current element. * @param reader XML reader. * @return Text of the element. * @throws XMLStreamException when the text cannot be read or XML is malformed. */ public static String loadElementText(XMLStreamReader reader) throws XMLStreamException { reader.next(); if (reader.isEndElement()) { return ""; } reader.require(XMLStreamConstants.CHARACTERS, null, null); String text = reader.getText(); reader.next(); reader.require(XMLStreamConstants.END_ELEMENT, null, null); return text; } }