Nav

DOM/XML Transformers

Mule contains several transformers that convert between a W3C DOM object and its serialized representation. The DomToXml transformer converts DOM objects to XML, the XmlToDom transformer converts XML strings to DOM objects, and the DomToOutputHandler transformer converts from a DOM to an OutputHandler serialization.

These transformers support the standard transformer attributes. In addition, they support the following configuration.

XML Module

The XML module contains a number of tools to help you read, transform, and write XML.

Transformers

These are transformers specific to this transport. Note that these are added automatically to the Mule registry at start up. When doing automatic transformations these will be included when searching for the correct transformers.

Name Description

dom-to-xml-transformer

Converts an XML payload (Document, XML stream, Source, etc.) to a serialized String representation.

dom-to-output-handler-transformer

Converts an XML payload (Document, XML stream, Source, etc.) to an OutputHandler for efficient serialization.

jxpath-extractor-transformer

The JXPathExtractor is a simple transformer that evaluates an XPath expression against the given bean and returns the result. By default, a single result will be returned. If multiple values are expected, set the singleResult property to false. In this case a List of values will be returned. Note the property is currently ignored for non-String/XML payloads.

xpath-extractor-transformer

The XPathExtractor is a simple transformer that evaluates an XPath expression using the JAXP libraries against the given bean and returns the result. By default, a String of the result will be returned. To return a Node, NodeSet, Boolean or Number result, the resultType attribute can be set.

object-to-xml-transformer

Converts a Java object to an XML representation using XStream.

xml-to-dom-transformer

Transforms an XML message payload to an org.w3c.dom.Document.

xml-to-object-transformer

Converts XML to Java bean graphs using XStream.

jaxb-object-to-xml-transformer

Converts a Java object to an XML representation using XStream.

jaxb-xml-to-object-transformer

Converts XML to Java bean graphs using XStream.

xslt-transformer

The XSLT transformer uses XSLT to transform the message payload. Transformation objects are pooled for better performance. You can set transformation context properties on the transformer and can pull these properties from the message using Expression Evaluators.

xquery-transformer

An Xml transformer uses XQuery to transform the message payload. Transformation objects are pooled for better performance. You can set transformation context properties on the transformer and can pull these properties from the message using Expression Evaluators.

xml-prettyprinter-transformer

Formats an XML string using the Pretty Printer functionality in org.dom4j.io.OutputFormat.

Filters

Filters can be used to control which data is allowed to continue in the flow.

Name Description

is-xml-filter

Accepts XML messages only. Alternatively, you can set the "not" attribute to filter out XML messages.

jxpath-filter

Filters messages based on XPath expressions using JXPath.

jaxen-filter

The Jaxen filter allows you to route messages based on XPath expressions. The Jaxen filter is generally faster than the JXPath filter and should be considered the first choice when using an XPath filter.

xpath-filter

The XPath filter uses the JAXP libraries to filter XPath expressions. Available as of Mule 2.2.

schema-validation-filter

The schema validation filter uses the JAXP libraries to validate your message against a schema. Available as of Mule 2.2.

Jaxb context

Table 1. Attributes of <jaxb-context…​>
Name Type Required Default Description

name

string

yes

The reference name of this context. Usually this will be referenced by a JAXB transformer

packageNames

string

yes

A colon-separated list of packages where JAXB classes live

Table 2. Child Elements of <jaxb-context…​>
Name Cardinality Description

Namespace manager

Table 3. Attributes of <namespace-manager…​>
Name Type Required Default Description

includeConfigNamespaces

boolean

no

false

If true, the top-level namespaces declared in this configuration file will be added to the Manager. Defaults to false.

Table 4. Child Elements of <namespace-manager…​>
Name Cardinality Description

namespace

0..*

Example

To use the DOM/XML transformers, you add them to your Mule XML configuration as follows:


         
      
1
2
3
<xm:dom-to-xml-transformer name="DomToXml"/>
<xm:xml-to-dom-transformer name="xmlToDom" returnClass="org.w3c.dom.Document" />
<xm:xml-to-output-handler-transformer name="xmlToOutputHandler" />

You can then reference them by name from endpoints:


         
      
1
2
3
4
<vm:inbound-endpoint name="testEndpoint" path="another.queue" connector-ref="vmConnector1" transformer-refs="DomToXml" />
...
<vm:outbound-endpoint ref="xml-dom-out" transformer-refs="xmlToDom" /> 
...

In this topic: