Reputation: 1
I was wondering if it was possible to place a restriction on 3 yes/no elements. I want atleasst one of the three to be selected as a 'yes'
The bpplena values are down below. Any idea on how to place this restriction?
<xs:element name="ResponseTime" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="TwelveHour" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
<xs:element name="SevenDay" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
<xs:element name="FortyEightHours" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
<xs:element name="Departure" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="250"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Upvotes: 0
Views: 186
Reputation: 111686
If you're using XML Schema 1.1, you can specify co-occurrence constraints via XPath 2.0 using xs:assert
like this (untested):
<xs:element name="ResponseTime" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="TwelveHour" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
<xs:element name="SevenDay" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
<xs:element name="FortyEightHours" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
<xs:element name="Departure" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="250"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:assert test="count((TwelveHour|SevenHour|FortyEightHours)[. = 'true']) gt 0"/>
</xs:complexType>
</xs:element>
If you're using XML Schema 1.0, you cannot express such a constraint in the schema, but you could use Schematron or check it at the application level.
Upvotes: 1