I have a OMElement
object and from that I want to get an InputStream
or reader object. What I want is to stream the xml
from the OMElement
which I have, without getting loaded into memory. I only could be able to get XMLStreamReader
object from that. But I can't find a way to get InputStream/Reader
out of that.
OMElement element /*I have this object */
XMLStreamReader xmlreader = element.getXMLStreamReaderWithoutCaching();
Can anyone please help me ? I really appreciate!
Thanks
PS: I have come a way to get an InputStream but it gives an exception which I need help to resolve it.
XMLStreamReader xmlReader = element.getXMLStreamReader(false);
try {
if (xmlReader.getEventType() == XMLStreamReader.START_DOCUMENT) {
xmlReader.next();
}
DataHandler handler = XMLStreamReaderUtils.getDataHandlerFromElement(xmlReader);
handler.getInputStream();
The call to getDataHandlerFromElement generate the exception javax.xml.stream.XMLStreamException: Error during base64 decoding
The purpose of the getDataHandlerFromElement method is to decode base64 encoded binary data contained in an element, which is not what you want.
Axiom currently doesn't have a streaming pull serializer (and I don't know any other XML library that supports this). It only supports serializing to XML in push mode, i.e. by writing to an OutputStream or Writer. You could do the serialization in a separate thread and use a PipedOutputStream/PipedInputStream (similar to what Activation does for DataHandler#getInputStream() for a DataHandler that is not backed by a DataSource). This would satisfy the constant memory requirement, but I guess that the overhead caused by using a separate thread would not be acceptable in your case.
I thought about the possibility to implement such a pull serializer in the past, and I think it's technically feasible to do that (without using a separate thread). Please open a feature request for Axiom so that we can implement that in one of the next releases. I think it would be an interesting addition to Axiom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With