在XSD中指定枚举中的值

log*_*eks 4 c# xsd

我在XSD文件中定义了如下的枚举

 <xs:simpleType name="PaperSizes">
    <xs:restriction base="xs:string">
      <xs:enumeration value="NUMBERS"></xs:enumeration>
      <xs:enumeration value="PICTURE"></xs:enumeration>
      <xs:enumeration value="RTF"></xs:enumeration>
    </xs:restriction>
Run Code Online (Sandbox Code Playgroud)

我需要覆盖编译器分配的详细值.即: - 对于NUMBERS,默认值为0.我需要值2.

我需要做些什么改变?

谢谢.

tom*_*ern 5

您不能为集合中的每个值设置不同的默认值.您可以使用"default"关键字为任何xsd简单类型设置一个默认值.

因此,如果您想在上面的示例中设置默认值,您可以执行以下操作:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element default="PICTURE" name="PaperSizes">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="NUMBERS" />
              <xs:enumeration value="PICTURE" />
              <xs:enumeration value="RTF" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.