学习 XML Schema,我希望能够在另一个元素中包含元素集合.看起来很简单,但不太确定如何做到这一点. 这是架构: xs:attributeGroup name="ProcedureMappingFragment" xs:attribute name="ParameterName" type="xs:s
这是架构:
<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>
而我正试图产生这样的东西:
<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.具体来说,它调用第二个ProcMapping元素对于命名空间MappingSection无效.
您需要设置minOccurs和maxOccurs.由于它们的默认值为1,因此只允许一个元素.所以我会定义:
<xs:complexType name="ProcedureMappingSection"> <xs:sequence> <xs:element name="ProcMapping" type="ProcedureMapping" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType>