XML 架构中的集合 [英] Collections in XML SChema
问题描述
学习 XML Schema,我希望能够在另一个元素中拥有元素的集合.看起来很简单,但不太确定如何去做.
Learning XML Schema, I want to be able to have collections of elements inside another element. Seems simple enough, not quite sure how to do it though.
这是架构:
<xs:attributeGroup name="ProcedureMappingFragment">
<xs:attribute name="ParameterName" type="xs:string" />
<xs:attribute name="TypeName" type="xs:string" />
<xs:attribute name="PropertyName" type="xs:string" />
<xs:complexType name="ProcedureMappingSection">
<xs:sequence>
<xs:element name="ProcMapping" type="ProcedureMapping" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ProcedureMapping">
<xs:attributeGroup id="two" ref="ProcedureMappingFragment" />
<xs:attribute name="ProcedureName" type="xs:string" />
</xs:complexType>
我正在尝试制作这样的东西:
And I am trying to produce something like such:
<MappingSection xmlns="http://tempuri.org/ServiceMapping.xsd">
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
</MappingSection>
但是它告诉我在 MappingSection 中我只能有一个 ProcMapping.具体来说,它调用了对命名空间 MappingSection 无效的第二个 ProcMapping 元素.
However it is telling me that I can only have one ProcMapping inside MappingSection. Specifically it is calling the 2nd ProcMapping element invalid for namespace MappingSection.
推荐答案
您需要设置 minOccurs
和 maxOccurs
.由于它们的默认值为 1,因此只允许使用一个元素.
You need to set the minOccurs
and maxOccurs
. Since they have a default value of 1, only one element is allowed.
所以我会定义:
<xs:complexType name="ProcedureMappingSection">
<xs:sequence>
<xs:element name="ProcMapping" type="ProcedureMapping" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
这篇关于XML 架构中的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!