How to make sure an element does not exist in XSD?

时间:2016-04-04 19:01:06

标签: xml xsd

Can I use maxOccurs="0"?

Example:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
      <xs:element name="child_name" type="xs:string" maxOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Do you have a better way for this?

1 个答案:

答案 0 :(得分:2)

好吧,只要minOccurs="0",您就可以设置maxOccurs="0",但更常见的是,您只需省略该元素以防止它出现:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="full_name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>