简体   繁体   English

BizTalk 2013r2 - 架构中的空元素

[英]BizTalk 2013r2 - Null elements in schemas

Trying to configure a schema so that it will always provide every element, regardless of whether it's populated or not.尝试配置模式,使其始终提供每个元素,无论它是否已填充。

I've tried setting the minOccurs to 1 and nillable to true on all elements in the schema, but it still doesn't make a difference.我已经尝试在架构中的所有元素上将 minOccurs 设置为 1 并将 nillable 设置为 true,但它仍然没有任何区别。 I've tested by passing through a message where the date element in the schema is null, but it still removes the element from the received message.我已经通过传递一条消息进行了测试,其中架构中的日期元素为空,但它仍然从收到的消息中删除了该元素。

The payload is picked up via a WCF-SQL Typed Polling port, with the created message then sent direct into the message box for picking up downstream (the process creates a canonical payload accepted by multiple other downstream integrations).有效负载通过 WCF-SQL 类型轮询端口获取,然后将创建的消息直接发送到消息框以获取下游(该过程创建一个规范的有效负载,被多个其他下游集成接受)。

Schema Example;模式示例;

<xs:element minOccurs="1" name="account_id" nillable="true" type="xs:string" /> 
<xs:element minOccurs="1" name="hus_id" nillable="true" type="xs:string" /> 
<xs:element minOccurs="1" name="date_left" nillable="true" type="xs:date" />

WCF-SQL (Typed Polling) Source Data Example; WCF-SQL(类型化轮询)源数据示例;

account_id - '267336302'
hus_id - ''
date_left - NULL

Received Message Example;收到的消息示例;

<account_id>267336302</account_id>
<hus_id/>

I've looked over the theory behind it, and in the first two pargraphs of this linked article, it's implied that these settings should make a difference.我已经查看了它背后的理论,在这篇链接文章的前两段中,暗示这些设置应该有所作为。

BizTalk Mapper: Working With Nillable Values (xsi:nil=”true”) (Sandro's WordPress blog) BizTalk Mapper:使用可空值 (xsi:nil=”true”) (Sandro 的 WordPress 博客)

Can anyone suggest how I receiving the message with all elements as required (null value or not).任何人都可以建议我如何根据需要接收包含所有元素的消息(是否为空值)。

I was unable to re-produce the issue you are having.我无法重现您遇到的问题。

I created a simple schema with on element which is a nillable date.我创建了一个带有 on 元素的简单模式,它是一个可空日期。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.Schema.SO72560754" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.Schema.SO72560754" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="NillableDate" nillable="true" type="xs:date" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

I made a second schema the same except I named the filed simply date.我制作了第二个相同的模式,只是我将提交的简单命名为日期。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.Schema.SO72560754_out" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.Schema.SO72560754_out" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Date" nillable="true" type="xs:date" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

And mapped the two together and deployed it to BizTalk.并将两者映射在一起并将其部署到 BizTalk。

I passed the following message through BizTalk with a XMLReceive Pipeline and the map on the Inbound Maps on the Receive Port.我通过 BizTalk 使用 XMLReceive Pipeline 和接收端口上的入站映射上的映射传递了以下消息。

<ns1:Root xmlns:ns1="http://Scratch2.Schema.SO72560754" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <NillableDate xsi:nil="true" />
</ns1:Root>

And got the expected output with the date field still there and being Nill.并获得了日期字段仍然存在且为 Nill 的预期输出。

<ns0:Root xmlns:ns0="http://Scratch2.Schema.SO72560754_out" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Date xsi:nil="true" />
</ns0:Root>

Note笔记

  1. that there is a difference between empty field (either <Date/> or <Date></Date> ) and a field that is Nill ( <Date xsi:nil="true" /> ).空字段( <Date/><Date></Date> )与空字段( <Date xsi:nil="true" /> )之间存在差异。 If you are doing XML validation the empty dates would fail.如果您正在执行 XML 验证,则空日期将失败。
  2. MinOccurs = 1 is the default value if nothing is specified.如果未指定任何内容,则 MinOccurs = 1 是默认值。
  3. If both source and destination elements are mandatory (eg must be there), then you don't need to do anything fancy, just map them as you would any other fields and no functoids necessary.如果源元素和目标元素都是强制性的(例如必须存在),那么您不需要做任何花哨的事情,只需像映射任何其他字段一样映射它们,并且不需要 functoid。 It is only if the source is optional and the destination is mandatory that you have to do some fancy workarounds.只有当源是可选的并且目标是强制性的时,您才必须做一些花哨的变通方法。

SQL SQL

Yes, with the SQL Bindings, if the field is NULL then it will omit the field.是的,使用 SQL 绑定,如果该字段为 NULL,那么它将省略该字段。 A quick and dirty fix would be just to add some concatenate functoids in the map as below and have it concatenate to an empty string.一个快速而肮脏的解决方法就是在地图中添加一些连接 functoid,如下所示,并将其连接到一个空字符串。 This will produce a XML payload like below.这将生成如下所示的 XML 有效负载。 Note: This would fail if you tried to validate it against the schema as an empty string is not a valid date, and also any numeric fields would also fail, but by default, BizTalk does not validate unless you tell it to.注意:如果您尝试根据架构验证它,因为空字符串不是有效日期,这将失败,并且任何数字字段也会失败,但默认情况下,BizTalk 不会验证,除非您告诉它。

在此处输入图像描述

<ns0:Root xmlns:ns0="http://Scratch2.Schema.SO72560754">
    <account_id>267336302 </account_id>
    <hus_id/>
    <date_left/>
</ns0:Root>

If you want to get XML that validates then you can follow Sandro's example, but all you have to do is rather than is the IsNill functoid, is to use the Logical Date Functoid and adjust the logic accordingly (as it inverts the true/false).如果您想获得验证的 XML,那么您可以按照 Sandro 的示例进行操作,但您所要做的就是使用逻辑日期 Functoid 而不是 IsNill functoid,并相应地调整逻辑(因为它反转了真/假) .

带有缺失日期逻辑的地图

That will produce那会产生

<ns0:Root xmlns:ns0="http://Scratch2.Schema.SO72560754" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <account_id>267336302</account_id> 
  <hus_id /> 
  <date_left xsi:nil="true" /> 
</ns0:Root>

You could also use the Logical String and Logical Number functoids if you have fields of that type that you also want to have nillable="true" on.如果您有该类型的字段,您还希望启用nillable="true" ,您也可以使用逻辑字符串和逻辑数字 functoid。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM