无效的子元素

时间:2017-01-11 20:54:46

标签: xml schema biztalk biztalk-2010 biztalk-schemas

我正在尝试在BizTalk 2010中对信封进行一些实验,当一条消息将由多个项目组成时。我有信封的架构如下:

信封:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://TestFromMSDN" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://TestFromMSDN" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo is_envelope="yes" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Envelope">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo body_xpath="/*[local-name()='Envelope' and namespace-uri()='http://TestFromMSDN']" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:any />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

单个项目的架构如下。每个信封可能包含多个项目。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://TestFromMSDN" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://TestFromMSDN" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Error">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ID" type="xs:int" />
        <xs:element name="Type" type="xs:int" />
        <xs:element name="Priority" type="xs:string" />
        <xs:element name="Description" type="xs:string" />
        <xs:element name="ErrorDateTime" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

当我尝试创建我的xml数据时,BizTalk不喜欢我的xml并且在我的第二个项目上有一条波浪线,说无效的子元素。

enter image description here

有人可以指出我的数据有什么问题吗?

<ns0:Envelope xmlns:ns0="http://TestFromMSDN">
  <ns0:Error>
    <ns0:ID>102</ns0:ID>
    <ns0:Type>0</ns0:Type>
    <ns0:Priority>High</ns0:Priority>
    <ns0:Description>Sproket query fails</ns0:Description>
    <ns0:ErrorDateTime>1999-05-31T13:20:00.000-05:00</ns0:ErrorDateTime>
  </ns0:Error>
  <ns0:Error>
    <ID>16502</ID>
    <Type>2</Type>
    <Priority>Low</Priority>
    <Description>Time threshold exceeded</Description>
    <ErrorDateTime>1999-05-31T13:20:00.000-05:00</ErrorDateTime>
  </ns0:Error>
</ns0:Envelope>

1 个答案:

答案 0 :(得分:0)

默认情况下,序列中的项目数为1.您应指定maxOccurs为无限制或您Envelope元素上预期的确切项目数(为清晰起见,我删除了注释) :

<xs:element name="Envelope">
  <xs:complexType>
    <xs:sequence maxOccurs="unbounded">
      <xs:any />
    </xs:sequence>
  </xs:complexType>
</xs:element>

另一个建议:如果您希望Error中只包含 Envelope元素,则更好的做法是指定<xs:Error/>而不是<xs:any/>

相关问题