我尝试用XSD验证一个可以包含float类型或单词"存在"的属性。在网上搜索后,我找到了这个解决方案,但是当我尝试这个模式时,它不起作用:
<pre lang="XML">
<xs:restriction base="xs:String">
<xs:pattern value="[0-9]| 'exist'"/>
</xs:restriction>
如何验证XML文件
您必须使用允许您在memberTypes
字段中指定另一个xs:simpleType
的xs:union
:
<xs:simpleType name="existType">
<xs:restriction base="xs:string">
<xs:enumeration value="exist" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="floatType">
<xs:union memberTypes="xs:float existType" />
</xs:simpleType>
然后在类型定义中使用此floatType
:
<xs:element name="Pre" maxOccurs="unbounded" type="floatType" />