简体   繁体   中英

Restrict attribute values in XML schema

Is it possible to restrict a combination of attribute values in XML schema? I have a tag with two attributes and I would like to permit some combinations of their values. Eg if attribute_1 has value "A", then attribute_2 must not have value "B".

In XSD 1.1 you can use assertions . Something like (untested):

<xs:element name="SomeType">
  <xs:complexType>
    <xs:attribute name="attribute_1" type="xs:string">
    <xs:attribute name="attribute_2" type="xs:string"/>
    <xs:assert test="if (@attribute_1 = 'A') then @attribute_2 != 'B' else true()"/>
  </xs:complexType>
</xs:element>

See more examples here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM