try {
// Get the prefix of the start tag
String prefix = reader.getPrefix();
// Stream the events to a writer starting with the current event
StreamingOMSerializer ser = new StreamingOMSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(baos, encoding);
ser.serialize(reader, writer, false);
writer.flush();
// Capture the written byte array as a ByteArrayDataSource
byte[] bytes = baos.toByteArray();
String text = new String(bytes, "utf-8");