如何验证在XSD中多次出现相同的元素

时间:2009-11-24 08:05:59

标签: xml xsd

我有一个XML文档,它有以下标记:

 <step id="navigation">
      ...
 </step id="background">

 <step id="content">
  ...
 </step>

如何确保内容,背景,导航等内容的步骤仅出现在我的文档中一次?

现在我有

 <xs:element name="step" maxOccurs="1">
   <xs:complexType>
       .....
   </xs:complexType>
 </xs:element>

由于

1 个答案:

答案 0 :(得分:1)

您应该为id属性定义唯一键。像这样:

<xsd:unique name="my_id">
  <xsd:selector xpath="//step"/>
  <xsd:field xpath="id"/>
</xsd:unique>