如何排除使用XSD在XML文件中的枚举值?
-
22-09-2019 - |
题
是否有可能以指定的标签或属性的的值不应该是这样强>的 SOME_VALUE 的
我有一种奇怪的要求,其中所述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
中排除的值。
此方法从由IBM 这本文使用溶液2。
使用正则表达式指定一种模式或在你的情况是什么模式不应该包含。
不隶属于 StackOverflow