簡體   English   中英

在 Biztalk 中將 XML Schema 轉換為 JSON 數組列表

[英]Conversion of XML Schema to JSON array list in Biztalk

我在下面定義了一個 xml scehema

<?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 arrays ?

您的 XSD 架構存在三個問題

  1. 您尚未定義目標命名空間。 這意味着當它通過 XML Receive 時,它將 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>

你得到一個 output

{
  "bblist": {
    "item": [
      "item_0"
    ]
  }
}

這更接近您預期的 JSON,它制作了一個重復元素的數組。

  1. 對於您期望的 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"
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM