Azure Logic Apps中XSD转换订单行XML格式异常求助
问题描述
使用Azure Logic Apps从MS Dynamics Business Central拉取数据,按XSD转换为XML后发送至外部系统。目前流程基本正常,但订单行转换异常:多条订单行的数据被合并到单个<orderline>节点中,而非生成多个独立的<orderline>节点。
相关XSD片段
<xs:element name="orderlines"> <xs:complexType> <xs:sequence> <xs:element name="orderline" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="type" type="xs:string"/> <xs:element name="whs" type="xs:string"/> <xs:element name="qty" type="xs:string"/> <xs:element name="partnr" type="xs:string"/> <xs:element name="snr" type="xs:string"/> <xs:element name="refnr" type="xs:string"/> <xs:element name="origincountry" type="xs:string"/> <xs:element name="commercialvalue" type="xs:string"/> <xs:element name="commoditycode" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>
期望生成的XML格式
<orderlines> <orderline> <type>REPLENISH</type> <whs>tes</whs> <qty>50</qty> <partnr>201.9004.8</partnr> <snr></snr> <refnr>efa79477-dfec-ee11-a1fd-7c1e52208373</refnr> <origincountry></origincountry> <commercialvalue>191.25</commercialvalue> <commoditycode></commoditycode> </orderline> <orderline> <type>REPLENISH</type> <whs>tes</whs> <qty>1</qty> <partnr>300.1351.1</partnr> <snr></snr> <refnr>b50570f3-7e7a-ef11-a671-6045bd999b21</refnr> <origincountry></origincountry> <commercialvalue>50.75</commercialvalue> <commoditycode></commoditycode> </orderline> <orderline> <type>REPLENISH</type> <whs>tes</whs> <qty>50</qty> <partnr>201.9004.8</partnr> <snr></snr> <refnr>1538e880-f9f0-ee11-a1fd-0022489bf1a3</refnr> <origincountry></origincountry> <commercialvalue>191.24</commercialvalue> <commoditycode></commoditycode> </orderline> </orderlines>
当前实际生成的XML格式
<orderlines> <orderline> <type>["REPLENISH"]</type> <whs>["tes","tes","tes","tes"]</whs> <qty>[50,1,50,50]</qty> <partnr>["201.9004.8","300.1351.1","201.9004.8","201.9004.8"]</partnr> <snr>[]</snr> <refnr> ["efa79477-dfec-ee11-a1fd-7c1e52208373","b50570f3-7e7a-ef11-a671-6045bd999b21","1538e880-f9f0-ee11-a1fd-0022489bf1a3","4438e880-f9f0-ee11-a1fd-0022489bf1a3"]</refnr> <origincountry>[]</origincountry> <commercialvalue>[191.25,50.75,191.24,191.24]</commercialvalue> <commoditycode>[]</commoditycode> </orderline> </orderlines>
解决方案
1. 修正数据输入结构
从Dynamics Business Central获取的订单行数据需为对象数组格式,而非每个字段单独的数组。需将返回的type: ["REPLENISH", ...]、whs: ["tes", ...]这类字段级数组,转换为如下结构:
[ { "type": "REPLENISH", "whs": "tes", "qty": "50", "partnr": "201.9004.8", ... }, { "type": "REPLENISH", "whs": "tes", "qty": "1", "partnr": "300.1351.1", ... } ]
2. 调整Logic Apps XML转换配置
- 使用Generate XML动作时,确保订单行的数据源是上述对象数组,而非单个包含数组字段的对象。
- 若使用XSLT转换,需添加循环逻辑遍历订单行数组,为每个对象生成独立的
<orderline>节点:
<xsl:for-each select="/root/orderlinesArray/orderline"> <orderline> <type><xsl:value-of select="type"/></type> <whs><xsl:value-of select="whs"/></whs> <qty><xsl:value-of select="qty"/></qty> <partnr><xsl:value-of select="partnr"/></partnr> <!-- 其他字段按此格式映射 --> </orderline> </xsl:for-each>
3. 验证XSD约束有效性
确认XSD中orderline节点的maxOccurs="unbounded"配置已被转换工具(如Logic Apps的XML生成器)正确识别,确保其支持生成重复节点。
内容的提问来源于stack exchange,提问作者jandemul
相关产品推荐
相关产品推荐

