Xml to Json
%dw 1.0
%output application/json
---
{
webKey: payload.Envelope.Body.GenericRequest.@webKey,
serviceId: payload.Envelope.Body.GenericRequest.Service.@ServiceId,
documents: payload.Envelope.Body.GenericRequest.Service.*Document map {
documentName: $[?($.@name == 'documentName')][0],
documentID: $[?($.@name == 'documentID')][0]
}
}
производит:
{
"webKey": "cs",
"serviceId": "GET_FILE",
"documents": [
{
"documentName": "abcd.pdf",
"documentID": "156"
},
{
"documentName": "efgh.pdf",
"documentID": "850"
}
]
}
Json to Xml
%dw 1.0
%output application/xml
%namespace soapenv http://schemas.xmlsoap.org/soap/envelope/
%namespace jcm http://www.oracle.com/JCM
---
{
soapenv#Envelope: {
soapenv#Header: '',
soapenv#Body:
jcm#GenericRequest @(webkey: payload.webKey):
jcm#Service @(ServiceId: payload.serviceId):
{(payload.documents map (
jcm#Document: $ mapObject {
jcm#Field @(name: $$): $
}
))}
}
}
производит:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<jcm:GenericRequest xmlns:jcm="http://www.oracle.com/JCM" webkey="cs">
<jcm:Service ServiceId="GET_FILE">
<jcm:Document>
<jcm:Field name="documentName">abcd.pdf</jcm:Field>
<jcm:Field name="documentID">156</jcm:Field>
</jcm:Document>
<jcm:Document>
<jcm:Field name="documentName">efgh.pdf</jcm:Field>
<jcm:Field name="documentID">850</jcm:Field>
</jcm:Document>
</jcm:Service>
</jcm:GenericRequest>
</soapenv:Body>
</soapenv:Envelope>