Limit attribute values ​​with xsd

I have an xsd file that looks like this:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Configurations">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Schema">
<xs:complexType>
<xs:sequence>
    <xs:element maxOccurs="unbounded" name="Table">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="Key">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Column" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:attribute name="Name" type="xs:string" use="required" />
                                    <xs:attribute name="Value" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="Name" type="xs:string" use="required" />
                        <xs:attribute name="Value" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="Name" type="xs:string" use="required" />
        </xs:complexType>
    </xs:element>
</xs:sequence>
<xs:attribute name="Name" type="xs:string" use="required" />
<xs:attribute name="ConnectionString" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>

   

And I just can't figure out how to create an xs:enumerationattribute for an Nameelement Schema, so only a few specified values ​​can be used for this attribute. I am not very good at xsd, a little help would be appreciated :)

+3
source share
1 answer

If you want to reuse the restricted type for all your attributes Name, add simpleTypeat the root level:

<xs:simpleType name="Name_type">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Foo" />
        <xs:enumeration value="Bar" />
        <xs:enumeration value="Baz" />
    </xs:restriction>
</xs:simpleType>

then refer to it as an attribute type Name:

<xs:attribute name="Name" type="Name_type" use="required" />
+4
source

All Articles