根据其他属性值验证 XML 属性 [英] Validate XML attribute based on other attribute value
问题描述
我有以下 XML.
<?xml version="1.0" encoding="utf-8" ?>
<Items>
<Item type="none" attNone1="test" attNone2="test3" />
<Item type="action" attAction1="test" attAction2="test2" />
</Items>
我需要根据一些规则创建一个 XSD:
I need to create an XSD based on some rules:
1) 属性类型"是必需的.
1) the attribute "type" is required.
2) 如果属性值应该是none"或action"
2) If the attribute value should be "none" or "action"
3) 如果属性值为none",我应该有另外两个必需的属性,attNone1"和attNone2".我不应该接受attAction1"或attAction2"
3) If the attribute value is "none" I should have two other required attribute, "attNone1" and "attNone2". I should not accept "attAction1" or "attAction2"
4) 如果属性值为action",我应该有另外两个必需的属性,attAction1"和attAction2".我不应该接受attNone1"或attNone2"
4) If the attribute value is "action" I should have two other required attribute, "attAction1" and "attAction2". I should not accept "attNone1" or "attNone2"
知道如何执行此 XSD 吗?
Any idea how to do this XSD?
提前致谢,
问候,
推荐答案
XSD 1.0 不允许共现约束",其中一个属性的类型取决于另一个属性的值.
XSD 1.0 does not allow "co-occurrence constraints" where the type of one attribute depends on the value of another.
在 XSD 1.1 中,您可以使用为此目的而发明的条件类型分配".Xerces 和 Saxon 目前支持 XSD 1.1.
In XSD 1.1 you can use "conditional type assignment" which was invented for this purpose. XSD 1.1 is currently supported in Xerces and Saxon.
这篇关于根据其他属性值验证 XML 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!