XSD Conditional Elements
-
I am attempting to make a schema where the valid options for a given enumeration are based on the content of another tag. Right now, I am attempting the following: I have an element with name="source", which can contain one of the following enumerated values {"src1", "src2"}. Now, what I want to do is to have another element with name="dependent", such that if tag "source" is set to "src1", the user has options {"opt1", "opt2"} for the "dependent" tag. If tag "source" is set to "src2", I would like the user to be able to set the "dependent" tag to one of {"opt3", "opt4"}. I am presently attempting the following:
xs:choice
xs:sequence
<xs:element name="source">
xs:simpleType
<xs:restriction base="xs:string">
<xs:enumeration value="src1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="dependent">
xs:simpleType
<xs:restriction base="xs:string">
<xs:enumeration value="opt1"/>
<xs:enumeration value="opt2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
xs:sequence
<xs:element name="source">
xs:simpleType
<xs:restriction base="xs:string">
<xs:enumeration value="src2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="dependent">
xs:simpleType
<xs:restriction base="xs:string">
<xs:enumeration value="opt3"/>
<xs:enumeration value="opt4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:choice>However, I am getting the error, "Elements with the same name and in the same scope must have the same type." Is there a way to accomplish what I am trying to do without forcing the tags in either option to have unique names? Thanks,
Sounds like somebody's got a case of the Mondays -Jeff