pfx-xml Component

Overview

The pfx-xml component provides XML marshalling and unmarshalling for integration routes. Use it to parse XML responses from external systems into Maps/Lists for further processing, or to serialize structured data back to XML.

URI pattern: pfx-xml:method


Methods

Method

Description

unmarshal

Parse an XML string in the body to a Map/List structure

marshal

Serialize a Map/List/POJO body to an XML string

No configuration parameters — pfx-xml operates directly on the message body.


Examples

Parse XML from external REST API

XML
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="importFromXmlApi">
        <from uri="timer://fetch?repeatCount=1"/>
        <to uri="pfx-rest:get?url={{api.url}}/products.xml"/>
        <to uri="pfx-xml:unmarshal"/>
        <split>
            <simple>${body[products][product]}</simple>
            <to uri="pfx-api:integrate?objectType=P&amp;mapper=productMapper"/>
        </split>
    </route>
</routes>

Parse XML file from inbound directory

XML
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="xmlFileImport">
        <from uri="file:{{inbound.path}}?include=.*\.xml"/>
        <to uri="pfx-xml:unmarshal"/>
        <split>
            <simple>${body[item]}</simple>
            <to uri="pfx-api:loaddata?objectType=P&amp;mapper=itemMapper"/>
        </split>
        <onCompletion onCompleteOnly="true">
            <to uri="pfx-api:internalCopy?label=Product"/>
        </onCompletion>
    </route>
</routes>

Serialize body to XML for outbound call

XML
<to uri="pfx-api:fetch?objectType=C&amp;filter=activeCustomers"/>
<to uri="pfx-xml:marshal"/>
<to uri="file:{{outbound.path}}?fileName=customers-${date:now:yyyyMMdd}.xml"/>

Common Pitfalls

  • unmarshal maps XML element names to Map keys. Nested elements become nested Maps; repeated elements become Lists.

  • Attribute values are typically stored under a @attributeName key — check the actual Map structure in a debug log before writing your mapper.

  • pfx-xml has no parameters — all configuration is done in the mapper/route, not on the component URI.