Reputation: 549
I have the following XSD currently.
<xsd:element name="ProcessingCode" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="000000" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="CardExpirationDate" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:pattern value="\d{4}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Now, I need to make CardExpirationDate as Mandatory only when the ProcessingCode value is 999999, else leave it optional. Kindly advise.
Upvotes: 0
Views: 308
Reputation: 163262
Assertions are an XSD 1.1 mechanism, so the [original] title of your post which talks about using assertions in XSD 1.0 doesn't make much sense.
If you want to do such an assertion in XSD 1.1, then the assertion goes on the element that is the common ancestor of ProcessingCode and CardExpirationDate. If we assume that these are sibling elements then the common parent element would have an an assertion such as
<xs:assert test="ProcessingCode != '999999' or exists(CardExpirationDate)"/>
Upvotes: 1