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

Examples

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"/>
</custom-transformer>

This allows you to cache XML events and replay them:

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

// start caching events
xsr.setTracking(true);

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

// Go back to the beginning of the XML document
xsr.reset();

....

// Don't cache events any more
xsr.setTracking(false);