I know that you can restrict value of an element by doing something as following.
<xs:element name="DataType">
<xs:simpleType>
<xs:restriction base="???">
<xs:enumeration value="integer" />
<xs:enumeration value="string" />
<xs:enumeration value="boolean" />
</xs:restriction>
</xs:simpleType>
<xs:element>
But what if I want to restrict the values to a list of XML schema primitive types such as xs:integer, xs:string, xs:boolean, etc. What should the @base attribute of restriction element be?
I want to do something like…
xs:integer
Do you mean that you want the values to be a list of certain type or do you want to have a list of types and allow that value can have any type which is mentioned in that list?
For the first one, use
<xs:list>for the second one, use<xs:union>.How to use
<xs:union>Unions are declared simply by listing the appropriate (simple) types in the
memberTypesattribute. You can also use named simple types that are defined in that schema file.This allows following kind of code
How to use
<xs:list>Lists are declared similarly to unions, but you cannot directly combine multiple types in the same list (using a type derived by a union as a base type of the list type should be possible though).
This allows following kind of code
The list separator characters are fixed: items must be separated with a whitespace character.
Edit to address the comment below
Sorry for misunderstanding your question. There is no built-in datatype that lists the type names, so you need to list all the names in an enumeration.
If you use an enumeration, you don’t actually need to use any special (more restricted) base type because only the valid values get listed. Plain old
xs:stringis good enough for thebaseattribute. Precisely speaking all the built-in type names are qualified names (or non-colonized names if namespace prefix is not counted) so the most appropriate base type should bexs:QNameorxs:NCName. You can use these types, if you would like to skip the enumeration and only want to assure that the contents could syntactically be a valid name for a type.Built-in schema datatypes (and their derivation hierarchy) can be seen from this image http://www.w3.org/TR/xmlschema-2/#built-in-datatypes