加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XML SChema中的集合

发布时间:2020-12-16 23:02:22 所属栏目:百科 来源:网络整理
导读:学习 XML Schema,我希望能够在另一个元素中包含元素集合.看起来很简单,但不太确定如何做到这一点. 这是架构: xs:attributeGroup name="ProcedureMappingFragment" xs:attribute name="ParameterName" type="xs:string" / xs:attribute name="TypeName" type
学习 XML Schema,我希望能够在另一个元素中包含元素集合.看起来很简单,但不太确定如何做到这一点.

这是架构:

<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读