json - 在 Biztalk 中将 XML Schema 转换为 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 架构存在三个问题
- 您尚未定义目标命名空间。这意味着当它通过 XML Receive 时,它将 MessageType 设置为不引用架构的默认值集。这意味着它可能不知道在 JSON 编码器中使用哪个模式。
MessageType Root Promoted http://schemas.microsoft.com/BizTalk/2003/system-properties
- 您在架构定义中使用了 a
<xs:all>
而不是 a<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,它制作了一个重复元素的数组。
- 您的结构对于您期望的 JSON 不正确,因为您在项目上有重复,而不是在 blist 上。
如果您将架构定义为
<?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"
]
}
推荐阅读
- c# - 如何绕过重复代码 Mongo/Core API
- xamarin.forms - 我怎样才能在 xamarin 表单中使用步进器发送属性 ID?
- python - 以点为单位的 pyplot 大小指的是什么?
- powershell - 为什么我不能同时使用 PowerShell 的 Start-Process 和 -Credential 和 -Verb 参数?
- java - 如果编辑类,如何创建 ArrayList 的安全保存并加载它?
- sql - 多部分标识符“列名”无法绑定问题
- sql - 仅当小数点后没有值时如何去除尾随小数点
- ajax - 在 laravel 中使用 Ajax 并给我未知的状态。为什么?
- mysql - 我无法在触发器中执行这两个语句
- java - 如何显示翻转大像素图过程的指示器?