BizTalk中XML模式到JSON数组列表的转换 [英] Conversion of XML Schema to JSON array list in Biztalk

查看:26
本文介绍了BizTalk中XML模式到JSON数组列表的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面定义了一个XML场景

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
    <xs:element name="Root">
        <xs:complexType>
            <xs:all>
                <xs:element name="bblist">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="item" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:all>
        </xs:complexType>
    </xs:element>
</xs:schema>

我要使用管道生成下面的Json。

{
    "bblist":
    [
        "13403"

    ]
}

但BizTalk管道将其转换为

{"bblist": "13403"}

只是想知道我的模式是否正确。我是否定义了xsd以正确生成Json数组?

xsd

您的推荐答案架构有三个问题

  1. 您尚未定义目标命名空间。这意味着当它通过XML接收时,它将MessageType设置为一组默认的值,该值不引用该架构。这意味着它可能不知道在JSON编码器中使用哪个架构。

MessageType Root Promoted http://schemas.microsoft.com/BizTalk/2003/system-properties

  1. 您在架构定义中使用了<xs:all>而不是<xs:sequence>。JSON编码器不能处理的内容。

如果您将架构定义为

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://bblist" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" targetNamespace="http://bblist" vc:minVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" name="bblist">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="1" maxOccurs="unbounded" name="item" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

有效负载为

<ns0:Root xmlns:ns0="http://bblist">
  <bblist>
    <item>item_0</item>
  </bblist>
</ns0:Root>

您将得到

的输出
{
  "bblist": {
    "item": [
      "item_0"
    ]
  }
}

这更接近您预期的JSON,因为它构成了重复元素的数组。

  1. 对于您期望的JSON,您的结构不正确,因为您在项目上有重复,而不在列表上。

如果您将架构定义为

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://bblist" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" targetNamespace="http://bblist" vc:minVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="blist" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

XML为

<ns0:Root xmlns:ns0="http://bblist">
  <blist>blist_0</blist>
</ns0:Root>

JSON为

{
  "blist": [
    "blist_0"
  ]
}

这篇关于BizTalk中XML模式到JSON数组列表的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆