如何使用XSD排除XML文件中的枚举值?
问题描述:
是否可以指定标记或属性的值应该不是 some_value?如何使用XSD排除XML文件中的枚举值?
我有一个奇怪的要求,其中xsd不知道发送给它的值。该特定标记的值可以是具有任何值的字符串,除了一个值(比如data_migration
)。
如果发送了该特定值,应确认发件人有错误。
是否可以指定此限制?
答
我不是正则表达式专家,但是这个simpleType使得所有以data_migration
开头的东西都无效。
<xs:simpleType name="notDataMigration">
<xs:restriction base="xs:string">
<xs:pattern value="^(?!data_migration).*" />
</xs:restriction>
</xs:simpleType>
答
我不知道你是否能明确排除的值。我不确定这是否有帮助,但您可以创建两个单独的枚举,然后创建枚举的联合。
<xsd:simpleType name="IncludedEnumType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="pending" />
<xsd:enumeration value="in_process" />
<xsd:enumeration value="failed" />
<xsd:enumeration value="unknown" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="ExcludedEnumType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="data_migration" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="CombinedEnumType">
<xsd:union memberTypes="IncludedEnumType ExcludedEnumType" />
</xsd:simpleType>
你要么IncludedEnumType
或CombinedEnumType
必要时使用。使用IncludedEnumType
显然会排除ExcludedEnumType
中的值。
此方法使用此article by IBM中的解决方案2。
+0
有用,但在这种情况下不;)所以+1。 – 2010-03-24 14:32:10
你不能这样做使用正则表达式。 – xcut 2010-03-24 14:19:47
请看上面由Jens Granlund选择的答案,相反...... – Yaneeve 2010-03-24 14:49:00
我站在更正的位置,我不知道在模式方言中团体可能被否定。 – xcut 2010-03-24 15:04:44