Mega Code Archive

 
Categories / XML Tutorial / XML Schema
 

By declaring a union, you can validate the values in your instance document against multiple types

<union memberTypes="whitespace separated list of types">  You specify the types you are combining by including the memberTypes attribute.  The value of the memberTypes attribute should be a whitespace-separated list of references to global <simpleType> definitions or built-in XML Schema datatypes.  The <union> declaration also allows you to specify your memberTypes by creating local <simpleType> definitions.  <simpleType name="UnknownString"   <restriction base="string"     <enumeration value="Unknown" />     </restriction> </simpleType> <simpleType name="UnknownOrFloatType"     <union memberTypes="float contacts:UnknownString"/> </simpleType> <element name="latitude" type="contacts:UnknownStringOrFloatType"/>  <element name="longitude" type="contacts:UnknownStringOrFloatType"/>  Some valid elements include the following:  <latitude>43.847156</latitude>  <longitude>Unknown</longitude>  Some invalid elements include these:  <latitude>unknown</latitude>  <longitude>43.847156 Unknown</longitude>