В XSD можно ограничивать атрибуты конкретными значениями;например:
<xs:attribute name="IDView">
<xs:simpleType>
<xs:restriction base="xs:string"> <!-- here you can set the base type -->
<xs:enumeration value="value1"/> <!-- add all possible values here -->
<xs:enumeration value="value2"/>
<xs:enumeration value="value3"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Здесь значение IDView
может быть только "value1" или "value2" или "value3".
Вот пример того, как сгенерировать эту частьXSD для всех значений enum
с XDocument
:
enum Values { value1, value2, value3 };
XNamespace xsd = "http://www.w3.org/2001/XMLSchema";
XDocument x = new XDocument(
new XElement(xsd + "attribute",
new XAttribute(XNamespace.Xmlns + "xs", "http://www.w3.org/2001/XMLSchema"),
new XAttribute("name", "IDView"),
new XElement(xsd + "simpleType",
new XElement(xsd + "restriction",
new XAttribute("base", "xs:string"),
Enum.GetNames(typeof(Values)).Select(a =>
new XElement(xsd + "enumeration",
new XAttribute("value", a.ToString())))))));