public static Reader getTextAsStream(OMElement element, boolean cache) { // If the element is not an OMSourcedElement and has not more than one child, then the most // efficient way to get the Reader is to build a StringReader if (!(element instanceof OMSourcedElement) && (!cache || element.isComplete())) { OMNode child = element.getFirstOMChild(); if (child == null) { return new StringReader(""); } else if (child.getNextOMSibling() == null) { return new StringReader(child instanceof OMText ? ((OMText)child).getText() : ""); } } // In all other cases, extract the data from the XMLStreamReader try { XMLStreamReader reader = element.getXMLStreamReader(cache); if (reader.getEventType() == XMLStreamReader.START_DOCUMENT) { reader.next(); } return XMLStreamReaderUtils.getElementTextAsStream(reader, true); } catch (XMLStreamException ex) { throw new OMException(ex); } }