I have such xsd type
<xsd:simpleType name="carsEnum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Seat"/>
<xsd:enumeration value="Opel"/>
</xsd:restriction>
</xsd:simpleType>
Now I can use it in such way – <xsd:attribute name="carModel" type="carsEnum"/>
How I can rebuild carEnum to use any another string?
As an example –
< ... carModel="Seat"/>
< ... carModel="Some string"/>
< ... carModel="Opel"/>
Of cause I can make type carsEnum as usual String, but it’s rather comfortable to use such construction in IDE Idea, because it show tool tips.
If I summarize your question what I understand is you want to maintain a list of possible values of an element cars, also want to accept any values appearing outside that bounded list. This can be achieved in XSD using
UNION. I have illustrated it with an example below.sample XML:
XSD:
In the above XSD, I am using multiple definitions of CAR, once as enum list and once as any string. Defining a UNION type combining these two, will be the
typefor cars.So
<carscan have values like: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 that means even special chars and numbers. We can restrict this by addingrestriction patternto only Alpha chars. Below is the XSD code:So possible values can be
Seat, Opel, "Any string but no Number", "Any string but no special char"replacing
by
doesn’t allow null string.
This is a way to redefine an element.. not being just stick to the enumeration list.
Now you have pattern also with enumeration list. Hope it helps.