我有以下xml:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Child name="MyType" compareMode="EQ">Child1</Child>
</Root>
通常为了验证这样一个 xml 会使用以下 xml 模式:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Child">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="compareMode" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我想限制Child元素的值并只允许以下内容:Child1、Child2和Child3。
我知道通常可以使用以下模式指定限制:
<xs:restriction base="xs:string">
<xs:enumeration value="Child1"/>
<xs:enumeration value="Child2"/>
<xs:enumeration value="Child3"/>
</xs:restriction>
在第一种情况下哪个限制是正确的?