I have a 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:enumeration
for the Name
attribute of the Schema
element, so that just a few specified values can be used for that attribute. I'm not any good at xsd, a little help would be appreciated:)
XSD Restrictions/Facets Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets.
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
XSD elements can be of type simpleType , complexType , or anyType . An element of type simpleType contains only text. It cannot have attributes and elements. An element of type complexType can contain text, elements, and attributes.
Fixed means the value in the XML document can only have the value specified in the XSD.
If you want to reuse the restricted type for all your Name
attributes, add a simpleType
at 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 reference it as the type of your Name
attributes:
<xs:attribute name="Name" type="Name_type" use="required" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With