WSO2 ESB从XML(多行)到JSON(无包装器)

WSO2 ESB从XML(多行)到JSON(无包装器),wso2,wso2esb,wso2ei,Wso2,Wso2esb,Wso2ei,我希望能在这里找到帮助。。。具体情况如下: 我从端点获取以下XML: <Entries> <Entry> <Customer>1</Customer> </Entry> <Entry> <Customer>2</Customer> </Entry> <Entries> 以下是我想要得到的JSON结果(没有包装):

我希望能在这里找到帮助。。。具体情况如下: 我从端点获取以下XML:

<Entries>
    <Entry>
        <Customer>1</Customer>
    </Entry>
    <Entry>
        <Customer>2</Customer>
    </Entry>
<Entries>
以下是我想要得到的JSON结果(没有包装):

有人知道怎么做吗?

非常感谢

我认为您必须首先操作xml(可能使用xslt中介)以这种方式格式化它

<jsonArray>
    <Customer>1</Customer>
    <Customer>2</Customer>
</jsonArray>

1.
2.
那么我想你会得到你期望的结果

例如,以下xslt可以完成这项工作

<xsl:stylesheet exclude-result-prefixes="xsl" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="yes"/>     
    <xsl:template match="/Entries">
        <xsl:element name="jsonArray">
            <xsl:copy-of select="./Entry/Customer" />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

谢谢阿努鲁达和尼古拉斯
你的回答激发了我的灵感,我想分享我所做的

我创建了这个序列,我将其与序列中介器一起重用:

<sequence name="toJSON" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
    <property name="result" scope="default" type="STRING" expression="json-eval($.Entries.Entry)"/>
    <payloadFactory media-type="json">
        <format>$1</format>
        <args>
            <arg evaluator="xml" expression="$ctx:result"/>
        </args>
    </payloadFactory>
</sequence>

$1
它工作得非常好,我甚至改变了我所有代理的顺序,甚至那些只返回一个结果的代理


谢谢你的灯光

您可以在foreach中介中使用有效负载中介从xml构造JSON。
<xsl:stylesheet exclude-result-prefixes="xsl" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="yes"/>     
    <xsl:template match="/Entries">
        <xsl:element name="jsonArray">
            <xsl:copy-of select="./Entry/Customer" />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
<sequence name="toJSON" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
    <property name="result" scope="default" type="STRING" expression="json-eval($.Entries.Entry)"/>
    <payloadFactory media-type="json">
        <format>$1</format>
        <args>
            <arg evaluator="xml" expression="$ctx:result"/>
        </args>
    </payloadFactory>
</sequence>