Search code examples
javaxmlmuletransformationesb

Mule ESB: xml to maps transformer produces empty hashmaps


The configuration of my flow is:

<flow name="addVendors" doc:name="addVendors">
        <file:inbound-endpoint path="/ws/esb/vendors/input/" moveToDirectory="/ws/esb/vendors/processed/" responseTimeout="10000" doc:name="File"/>
        <file:file-to-string-transformer mimeType="text/xml" doc:name="File to String"/>
        <jdbc-ee:xml-to-maps-transformer encoding="UTF-8" mimeType="text/xml" doc:name="XML to Maps"/>
        <component class="com.myapp.integration.VendorsHelper" doc:name="Java"/>
        <file:outbound-endpoint path="/ws/esb/vendors/output" responseTimeout="10000" doc:name="File"/>
    </flow>

I'm trying to send the following xml:

<?xml version="1.0"?>
<book>
        <note id="1">
            note1
            <to>Tove</to>
            <from>Jani</from>
            <heading>Reminder</heading>
            <body>Don't forget me this weekend!</body>
            <author>Some author</author>
        </note>
        <note id="2">
            note2
            <to>Mark</to>
            <from>Smith</from>
            <heading>Invitation</heading>
            <body>Invitation for birthday!</body>
            <author>Some author</author>
        </note>
</book>

The problem is that I get two empty hashmaps after xml-to-maps transformation. What is incorrect in my code? how to debug it?


Solution

  • As explained in the documentation of the transformer, the XML transformed by the xml-to-maps transformer must be compliant to a specific schema (provided in the documentation).

    Here is an example of a valid XML document:

    <table>
      <record>
        <field name="id" type="java.math.BigDecimal">0</field>
        <field name="name" type="java.lang.String">hello</field>
      </record>
    </table>
    

    So you need to use the XSL-T transformer to transform your XML into the expected XML format and then you can use the transformer.