Access Keys:
Skip to content (Access Key - 0)
Cancel    
Cancel   
 

XML Module Reference

Mar 06, 2008 13:22

Robin Pille

Jan 30, 2014 18:52

Mulesoft Current Mule Documentation

XML Module Reference

Mulesoft Documentation Page

Contents

XML Module Reference

The XML module contains several tools to help you read, transform, and write XML.

In addition to the functionality described on this page, you can also use the SXC Module Reference, which enables efficient XPath XML routing.

 Contents

 

XML Formats

Mule understands a wide variety of XML Java representations:

  • org.w3c.dom.Document, org.w3c.dom.Element
  • org.dom4j.Document
  • javax.xml.transform.Source
  • InputStream, String, byte[]
  • OutputHandler
  • XMLStreamReader
  • org.mule.module.xml.transformer.DelayedResult

Any transformer that accepts XML as an input will also understand these types.

 

Transformers

There are several standard transformers that process XML inside Mule.

Transformer

Description

XmlToObject <-> ObjectToXml

Converts XML to a Java object and back again using XStream.

JAXB XmlToObject <-> JAXB ObjectToXml

Converts XML to a Java object and back again using the JAXB binding framework (ships with JDK6)

XSLT

Transforms XML payloads using XSLT.

XQuery

Transforms XML payloads using XQuery.

DomToXml <-> XmlToDom

Converts DOM objects to XML and back again.

XmlToXMLStreamReader

Converts XML from a message payload to a StAX XMLStreamReader.

XPath Extractor

Queries and extracts object graphs using XPath expressions using JAXP.

JXPath Extractor

Queries and extracts object graphs using XPath expressions using JXPath.

XmlPrettyPrinter

Allows you to output the XML with controlled formatting, including trimming white space and specifying the indent.

Efficient Transformations with DelayedResult

Mule contains a special XML output format called DelayedResult. This format allows very efficient XML transformations by delaying any XML serialization until an OutputStream is available.

For example, here is an XSLT transformer set up to use DelayedResult:

If the result of this transformation were being sent to an HTTP client, the HTTP client would ask Mule for an OutputHandler and pass in the OutputStream to it. Only then would Mule perform the transformation, writing the output directly to the OutputStream.

If DelayedResult were not used, the XML result would first be written to an in-memory buffer before being written to the OutputStream. This will cause your XML processing to be slower.

 

Filters

The XML module contains various XPath filters. For general details on how to use filters, see Filters.

XPath Filter

The XPath filter uses the JAXP libraries to filter XPath expressions. This filter is available as of Mule 2.2.

The following configuration routes messages to the "vm://echo" endpoint when the value of "/e:purchaseOrder/e:shipTo/@country" is "US".

 

Schema Validation Filter

The schema validation filter uses the JAXP libraries to validate your message against a schema. 

The following configuration will validate your message against a schema called schema.xsd and a schema called anotherSchema.xsd.

 

Jaxen Filter

The Jaxen filter uses the Jaxen library to filter messages based on XPath expressions.

The following configuration routes messages to the "vm://echo" endpoint when the value of "/e:purchaseOrder/e:shipTo/@country" is "US".

 

JXPath Filter

The JXPath filter is very similar to the Jaxen filter. It is still used for historical purposes (it existed before the Jaxen filter).

 

Splitters

The XML module contains two splitters, a filter-based splitter and a round-robin splitter.

 

XML Parsers

In most cases, SAX is used to parse your XML. If you are using CXF or the XmlToXMLStreamReader, Stax is used instead.

If you're using SAX, the SAX XML parser is determined by your JVM. If you want to change your SAX implementation, see http://www.saxproject.org/quickstart.html.