Nav

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:


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

You can also create a "reversible" XMLStreamReader:


         
      
1
2
3
<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:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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);

In this topic: