【发布时间】:2018-04-17 18:36:18
【问题描述】:
我已经在网上搜索了一段时间,据我所知,使用 XSD 1.0 无法实现我想要的。我的要求是:
我们有一个 .xml,它在导入到 excel 时会创建下表:
要求只有一个,即Bird 1,2,3下的值限制在每个特征的每个Min和Max的范围内。
例如,鸟 1 的体重必须在 10-20 之间,但鸟 1 的高度必须在 3-9 之间。
在 Bird 3 下,体重和身高不是有效的方法,因为它们超出了它们的最小-最大范围。
现在我需要制作一个可以导入 Excel 的 XSD 文件,并且它会创建使上述工作生效的限制。
我做的XSD是:
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="Row" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Feature"/>
<xs:element type="xs:int" name="Min"/>
<xs:element type="xs:int" name="Max"/>
<xs:element name="Bird 1">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="X"/> <!-- X= The Min value -->
<xs:maxInclusive value="Y"/> <!-- Y= The Max value -->
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Bird 2">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="X"/> <!-- X= The Min value -->
<xs:maxInclusive value="Y"/> <!-- Y= The Max value -->
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Bird 3">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="X"/> <!-- X= The Min value -->
<xs:maxInclusive value="Y"/> <!-- Y= The Max value -->
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
上面的 XSD 仅在限制值中有固定数字时才有效。
理想情况下,我希望限制 minInclusive 和 maxInclusive 值指向 Min Max 元素。
如果我可以使用 XSD 1.1 或其他类似 schematron 的东西,那将是可行的。但是因为我需要将 xsd 导入 Excel,所以我不得不使用 XSD 1.0。
我目前正在尝试根据示例 sample 找出一种使用 Key 和 Key-ref 的方法,但到目前为止我没有运气。
有任何建议或解决方法来完成这项工作???
提前谢谢你
【问题讨论】:
标签: xml excel xsd xsd-validation restrictions