mule - 在 mule 4 中将带有 CDATA 的 SOAP 响应转换为 JSON
问题描述
我有这种来自骡子 4 的肥皂反应的结果。
{ body:<web:getRoutesResponse xmlns:web="http://www.example.org/Bookings/"> <out><![CDATA[<?xml version="1.0"encoding="utf-8"?><ROUTELIST><ROUTEINFO> <ORIGIN>MY-KUL</ORIGIN><DESTINATION>SG-BEU</DESTINATION><ROUTEINFO></ROUTELIST>]]></out> </web:getRoutesResponse> , headers: [], attachments: [] }
我想在这个 json 输出中制作具有起点和终点的数组
[ { "origin": "MY-KUL", "destination": "SG-BEU" } ]
解决方案
你可以试试这样的东西。与 Ale 的先前答案相同,但使用扫描来搜索某些文本模式之间的内容。
输入
{
"body": "<web:getRoutesResponse xmlns:web=\"http: //www.example.org/Bookings/\"> <out><![CDATA[<?xml version=\"1.0\"encoding=\"utf-8\"?><ROUTELIST><ROUTEINFO> <ORIGIN>MY-KUL</ORIGIN><DESTINATION>SG-BEU</DESTINATION><ROUTEINFO></ROUTELIST>]]></out> </web:getRoutesResponse>",
"headers": [],
"attachments": []
}
脚本
%dw 2.0
output application/json
var a = read(payload.body, "application/xml").getRoutesResponse.out
---
[{
origin: (a scan(/\<ORIGIN>(.+?)\<\/ORIGIN>/))[0][1],
desination: (a scan(/\<DESTINATION>(.+?)\<\/DESTINATION>/))[0][1]
}]
输出
[
{
"origin": "MY-KUL",
"desination": "SG-BEU"
}
]
推荐阅读
- facebook - og:image URL 错误:https://mydomain/session/upload/undefined 无法作为图像处理,因为它具有无效的内容类型
- windows - 剪贴板:无法将已注册的剪贴板格式枚举为本地系统
- azure-ad-b2c-custom-policy - 注册时的 MFA 和 ForeReseetPassword 仅登录
- python - 我们可以在python的if-else语句中使用break语句吗
- python - 需要帮助从具有时间线和计数的字典列表中提取数据
- java - 如何从 JPA 中的两个表值中删除数据?
- react-native - 模拟反应导航共享元素的正确方法
- c++ - 万花筒教程找不到头文件`ExecutorProcessControl.h`
- amazon-dynamodb - 查询 DynamoDB GSI 以查找匹配子字符串的选项有哪些?
- javascript - 如何在 d3.js 中使用 .scale 和 .translate?