Contact Us 1-800-596-4880

XmlToXMLStreamReader Transformer

The XmlToXMLStreamReader transformer converts XML representations to a StAX XMLStreamReader. XMLStreamReaders allow XML to be parsed as a series of events that are "pulled" from the stream. It is very efficient.

This transformer supports the following input formats:

  • javax.xml.transform.Source.class

  • org.xml.sax.InputSource.class

  • org.dom4j.Document.class

  • org.w3c.dom.Document.class

  • org.w3c.dom.Element.class

  • org.mule.module.xml.transformer.DelayedResult.class

  • String

  • byte[]

  • InputStream


To use the transformer, you must declare a custom transformer element:

<custom-transformer name="XmlToXSR" class="org.mule.module.xml.transformer.XmlToXMLStreamReader"/>

You can also create a "reversible" XMLStreamReader:

<custom-transformer name="XmlToXSR" class="org.mule.module.xml.transformer.XmlToXMLStreamReader">
   <property key="reversible" value="true"/>

This allows you to cache XML events and replay them:

MuleMessage message = ...;
ReversibleXMLStreamReader xsr = (ReversibleXMLStreamReader) message.getPayload();

// start caching events

// parse....
while (...) {; }

// Go back to the beginning of the XML document


// Don't cache events any more
View on GitHub