首页 > 解决方案 > WSO2 Enterprise Integrator 6.6.0 使用 XSLT 将 XML 响应转换为 Json

问题描述

我从 WSO2 企业集成器中的端点以 XML 形式收到响应。我也可以将它作为 Json 来获取。但我需要为我的客户端应用程序做出适当的响应(添加更多参数)。这是我从端点得到的 xml 响应。

<jsonObject>
<ddd>
    <__type>Title</__type>
    <AccountNo/>
    <AccountExists>1</AccountExists>
    <Name>user name</ConsumerName>
    <Address> user address</ConsumerAddress>
    <TotalDue>1000.38</TotalDue>
    <LastBillingCycleAmount/>
    <ID>150</ID>
</d>

这也是我可以从端点检索的 json 输出

{
    "ddd": {
        "__type": "Title",
        "AccountNo": null,
        "AccountExists": 1,
        "Name": "user name",
        "Address": "address",
        "TotalDue": "1000.38",
        "LastBillingCycleAmount": null,
        "ID": 150
    }
}

我需要这样的转换响应。

{
    "AccountNo": "response_data",
    "ConsumerName": "response_data",
    "ConsumerAddress": "response_data",
    "TotalDue": "response_data",
    "additional_para1": "my_data",      // parameter that i want to add manually
    "additional_para2": "my_data",      // parameter that i want to add manually
    
}

标签: jsonxmlxslttransformationwso2ei

解决方案


您可以使用数据映射器调解器 [1] 将输入映射到所需的输出。然后使用丰富的调解器 [2] 通过添加您自己的值来丰富生成的有效负载

[1]-https://ei.docs.wso2.com/en/7.1.0/micro-integrator/references/mediators/data-Mapper-Mediator/

[2]-https://docs.wso2.com/display/EI620/Enrich+Mediator


推荐阅读