0

Is it possible to write conditional based xsd. I have list of countries defined in my xsd, If user choose country as UNITED STATES, xsd should allow user to select the states which belong to above choosen country, Else it should show validation error. Below example, perfectly allow user to select country and state for the below list, But it does not perform any validations agaist country. If you have any suggestions to write choice based xsd, Please let me know. Please note that, I have tried <xs:choice>, it does not work for this scenario.

<xs:complexType name="header-type">
    <xs:sequence>
        <xs:element name="country" type="country-type" />
        <xs:element name="states" type="state-type" />
    </xs:complextType>
        <xs:simpleType name="country-type">
            <xs:restriction base="xs:string">
                <xs:enumeration value="UNITEDSTATES"></xs:enumeration>
                <xs:enumeration value="AUS"></xs:enumeration>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="state-type">
            <xs:restriction base="xs:string">
                <xs:enumeration value="California"></xs:enumeration>
                <xs:enumeration value="Sydney"></xs:enumeration>
                <xs:enumeration value="Texas"></xs:enumeration>
        </xs:simpleType>
user487772
  • 8,800
  • 5
  • 47
  • 72
akr rd
  • 1
  • 1
  • 1
  • possible duplicate of [Dynamic enumeration restriction using XSD 1.1](http://stackoverflow.com/questions/13653995/dynamic-enumeration-restriction-using-xsd-1-1) – sergioFC Aug 29 '14 at 21:54
  • I think this is only possible if you're using XSD 1.1. Have a look at [this question](http://stackoverflow.com/questions/13653995/dynamic-enumeration-restriction-using-xsd-1-1) and its answers. – sergioFC Aug 29 '14 at 21:55
  • Thank you so much for your help. I am on Java, I see[link](http://stackoverflow.com/questions/13653995/dynamic-enumeration-restriction-using-xsd-1-1), This is only possible for .Net, Correct me if i am wrong here. using , will solve for .net users. – akr rd Aug 29 '14 at 22:32
  • xs:assert its an element of the [XML Schema 1.1 specification](http://www.w3.org/TR/xmlschema11-1/), the element not depends on the language (Java, .net ...). XSD 1.1 it's implemented in Altova, Saxon and xerces processors, if you're in java I think you can use at least Saxon and Xerces. – sergioFC Aug 29 '14 at 22:53

0 Answers0