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 |
|---|---|
|
|
Parse an XML string in the body to a Map/List structure |
|
|
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
<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&mapper=productMapper"/>
</split>
</route>
</routes>
Parse XML file from inbound directory
<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&mapper=itemMapper"/>
</split>
<onCompletion onCompleteOnly="true">
<to uri="pfx-api:internalCopy?label=Product"/>
</onCompletion>
</route>
</routes>
Serialize body to XML for outbound call
<to uri="pfx-api:fetch?objectType=C&filter=activeCustomers"/>
<to uri="pfx-xml:marshal"/>
<to uri="file:{{outbound.path}}?fileName=customers-${date:now:yyyyMMdd}.xml"/>
Common Pitfalls
-
unmarshalmaps XML element names to Map keys. Nested elements become nested Maps; repeated elements become Lists. -
Attribute values are typically stored under a
@attributeNamekey — check the actual Map structure in a debug log before writing your mapper. -
pfx-xmlhas no parameters — all configuration is done in the mapper/route, not on the component URI.