Created
October 31, 2016 05:59
-
-
Save wkoszycki/a1c2ef21637c94cf41dcb88b3756607f to your computer and use it in GitHub Desktop.
sample transformation from xml to json using wso2 enrich
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<sequence name="GetOrderIdsForDataExtractionRequest_Transform" | |
trace="disable" | |
xmlns:orders="http://imshealth.com/bdf/esb/client/orders/schemas/" | |
xmlns="http://ws.apache.org/ns/synapse"> | |
<!--Remove wrapper element (GetOrderIdsForDataExtraction) by replacing it with his child (Deliverables)--> | |
<!--example input--> | |
<!--<orders:GetOrderIdsForDataExtraction xmlns:orders="http://imshealth.com/bdf/esb/client/orders/schemas/"> | |
<orders:Deliverables> | |
<orders:DeliverableCd>TDW</orders:DeliverableCd> | |
</orders:Deliverables> | |
<orders:Deliverables> | |
<orders:DeliverableCd>NPA</orders:DeliverableCd> | |
</orders:Deliverables> | |
</orders:GetOrderIdsForDataExtraction>--> | |
<!--Check wheter Deliverables has only one child node--> | |
<filter xpath="not(boolean(//orders:Deliverables[2]))"> | |
<then> | |
<!--Manually prepare one element json array--> | |
<payloadFactory media-type="json"> | |
<format> | |
{ | |
"Deliverables": [ | |
{ | |
"DeliverableCd": "$1" | |
} | |
] | |
} | |
</format> | |
<args> | |
<arg expression="//orders:Deliverables/orders:DeliverableCd[1]"/> | |
</args> | |
</payloadFactory> | |
</then> | |
</filter> | |
<!--Automatically transform xml -> json--> | |
<enrich> | |
<source type="custom" xpath="//orders:Deliverables"/> | |
<target type="body" /> | |
</enrich> | |
<call-template target="tnscommon_PrepareRequest"> | |
<with-param name="dataFormatParam" value="json"/> | |
</call-template> | |
</sequence> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment