To summarize your question, I understand that you want to keep a list of the possible values โโof elementary cars, also want to accept any values โโthat appear outside this limited list. This can be achieved in XSD using UNION . I illustrated this with the example below.
XML sample:
<?xml version="1.0" encoding="utf-8"?> <cars>ssd</cars>
XSD:
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="cars" type="carsType"/> <xs:simpleType name="carsType"> <xs:union memberTypes="carsEnum carsAnyString"/> </xs:simpleType> <xs:simpleType name="carsEnum"> <xs:restriction base="xs:string"> <xs:enumeration value="Seat"/> <xs:enumeration value="Opel"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="carsAnyString"> <xs:restriction base="xs:string"/> </xs:simpleType> </xs:schema>
In the above XSD, I use several CAR definitions, once as a list of enumerations and once as any line. The definition of the UNION type that combines the two will be type for cars.
So, <cars can have values โโsuch as: Seat, Opel, anyOtherCar, AnyString2 ..
I would also like to mention a way to control the value of ANY STRING . Above XSD can accept any string, which means even special characters and numbers. We can limit this by adding a restriction pattern only to Alpha characters. The following is the XSD code:
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="cars" type="carsType"/> <xs:simpleType name="carsType"> <xs:union memberTypes="carsEnum carsAnyAlphaString"/> </xs:simpleType> <xs:simpleType name="carsEnum"> <xs:restriction base="xs:string"> <xs:enumeration value="Seat"/> <xs:enumeration value="Opel"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="carsAnyAlphaString"> <xs:restriction base="xs:string"> <xs:pattern value="[A-Za-z]*"/> </xs:restriction> </xs:simpleType> </xs:schema>
Thus, the possible values โโcan be Seat, Opel, "Any string but no Number", "Any string but no special char"
replacement
`<xs:pattern value="[A-Za-z]*"/>`
by
<xs:pattern value="[A-Za-z]+"/>
does not allow an empty string. This is a way to override an item. Don't just stick to the list of listings.
You now have an enumerated template. Hope this helps.