如果XSD没有指定maxOccurs,那么XML文档中元素的最大数目是多少?



我有一个在文档中定义多个元素的XSD模式。我期望的两组元素是集合。一组元素的定义如下:

<xsd:element name="Prospects" minOccurs="0">
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="ROW" minOccurs="0" maxOccurs="unbounded">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ID" type="xdv:guidKey" nillable="false" />
          <xsd:element name="Name" minOccurs="0">
            <xsd:complexType>
              <xsd:simpleContent>
                <xsd:extension base="xdv:stringLen50">
                  <xsd:attribute name="origVal" type="xdv:stringLen50" use="optional" />
                </xsd:extension>
              </xsd:simpleContent>
            </xsd:complexType>
          </xsd:element>
          ... more stuff...
    </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string" use="required" fixed="Prospects" />
  <xsd:attribute name="alias" type="xsd:string" use="required" fixed="Prospects" />
  <xsd:attribute name="keys" type="xsd:string" use="required" fixed="ProposalID" />
  <xsd:attribute name="codeTableColVal" type="xdv:codeTableColVal" use="optional" />
</xsd:complexType>

另一组元素看起来像这样:

<xsd:element name="Employees" minOccurs="0" maxOccurs="1">
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="ROW">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ID" type="xdv:guidKey" nillable="false" />
          <xsd:element name="Seq" type="xdv:guidKey" nillable="false" />
          <xsd:element name="CompanyName" minOccurs="0">
            <xsd:complexType>
              <xsd:simpleContent>
                <xsd:extension base="xdv:stringLen32">
                  <xsd:attribute name="origVal" type="xdv:stringLen32" use="optional" />
                </xsd:extension>
              </xsd:simpleContent>
            </xsd:complexType>
          </xsd:element>
          ... more stuff...
    </xsd:element>
  </xsd:sequence>
  <xsd:attribute name="name" type="xsd:string" use="required" fixed="Employees" />
  <xsd:attribute name="alias" type="xsd:string" use="required" fixed="Employees" />
  <xsd:attribute name="keys" type="xsd:string" use="required" fixed="OpportunityID,Seq" />
  <xsd:attribute name="codeTableColVal" type="xdv:codeTableColVal" use="optional" />
</xsd:complexType>

主要区别在于前者为prospect指定minOccurs="0"并且没有max发生,然后为ROW定义minOccurs=0和maxOccurs=unbounded。

对于后者,它定义了Employees的minOccurs=0和maxOccurs=1,而对于ROW,它没有定义minOccurs或maxOccurs。

当我运行实用程序Xsd2Code时,它生成我的c#代码,对于前景,它创建一个具有ROWs集合的前景属性(As a List()),但对于雇员,它创建一个具有ROW属性的雇员属性,而不是集合。

我的问题是:这个的模式规则是什么?既然没有定义在ROW上的maxOccurs为employee执行最小值和最大值家长申请还是集合申请?

我试图确定是否正在创建我的代码的实用程序是错误的,或者如果。xsd文件是错误的。

不指定maxOccurs时默认为maxOccurs = "1"

来自XML Schema Indicators。

Occurrence指示符用于定义元素可以发生的频率发生。

注:对于所有"顺序"one_answers"组"指标(any, all, choice,序列、组名和组引用)的默认值maxOccurs和minOccurs是1.

最新更新