XML模式检查错误

Geo*_*ge2 2 xml schema

我使用以下架构来检查以下XML文件.我发现当People元素中有多个Information元素时,模式检查将失败.为什么以及如何解决它(我想让People元素能够嵌套多个信息项)?

XML Schema文件:

  <xs:element name="People">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Information">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Name" type="xs:string"/>
            </xs:sequence>
            <xs:attribute name="Id" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
Run Code Online (Sandbox Code Playgroud)

XML文件(模式检查将失败):

  <People>
    <Information Id="1">
      <Name>John</Name>
    </Information>
    <Information Id="2">
      <Name>Mike</Name>
    </Information>
  </People>
Run Code Online (Sandbox Code Playgroud)

XML文件(模式检查会成功):

  <People>
    <Information Id="1">
      <Name>John</Name>
    </Information>
  </People>
Run Code Online (Sandbox Code Playgroud)

乔治,提前谢谢

Mor*_*075 6

如果您没有为序列指定minOccurs和maxOccurs,则默认值为1.

<xs:element name="Information" minOccurs = "1" maxOccurs = "unbounded">
Run Code Online (Sandbox Code Playgroud)