如果 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>
主要区别在于,前者为 Prospects 指定 minOccurs="0" 并且不出现最大值,然后为 ROW 定义 minOccurs=0 和 maxOccurs=unbounded。
对于后者,它为员工定义了 minOccurs=0 和 maxOccurs=1,而对于 ROW,它没有定义 minOccurs 或 maxOccurs。
当我运行实用程序 Xsd2Code
时,它会生成我的 C# 代码,对于 Prospects,它会创建一个带有 ROWs 集合(作为 List())的 Prospects 属性,但对于Employees,它会创建一个具有 ROW 属性的员工属性,而不是集合。
我的问题:这个的架构规则是什么?既然没有 在员工的 ROW 上定义的 maxOccurs 会计算该员工的最小值和最大值 父应用还是应该是一个集合?
我试图确定创建代码的实用程序是否错误或者 .xsd 文件是否错误。
I have an XSD schema that defines multiple elements in a document. Two sets of the elements I expect to be collections. One set of elements is defined like follow:
<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>
The other set of elements looks like this:
<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>
The primary difference being that the former specifies minOccurs="0" for Prospects and no max occurs, then for ROW it defins minOccurs=0 and maxOccurs=unbounded.
For the latter it defines minOccurs=0 and maxOccurs=1 for Employees and for the ROW it does not define a minOccurs or maxOccurs.
When I run the utility program, Xsd2Code
, and it generates my C# code, for the Prospects, it creates a Prospects property with a ROWs collection (As a List()) but for the Employees it create an Employee property with a ROW property, not a collection.
My question: whats is the schema rule for this? Since there is no
maxOccurs defined on ROW for employee does the min and max for the
parent apply or should it be a collection?
I am trying to determine if the utility that is creating my code is wrong or if the .xsd file is wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果未指定
maxOccurs
,则默认值与maxOccurs = "1"
相同。来自 XML 架构指示器。
The default if
maxOccurs
is not specified is the same asmaxOccurs = "1"
.From XML Schema Indicators.