xml - XML Schema - 两个两个元素的键约束
问题描述
我的 .xml 文件是这样的:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file.xsd">
<parent id="">
<child>
<part>A1</part>
</child>
</parent>
<another-parent name="AAA">
<part name="A1"/>
<part name="A2"/>
<part name="A3"/>
</another-parent>
<another-parent name="BBB">
<part name="A1"/>
</another-parent>
</root>
我想要的是:
name
of<another-parent>
必须是唯一的。没关系。name
of<part>
必须是唯一name
的<another-parent>
。没关系。<part name="A1">
inside<child>
必须是<another-parent>
. 而我不能那样做。
对于第一点,我使用了以下内容并且它可以正常工作。
<xsd:key name="anotherParentKey">
<xsd:selector xpath="another-parent"/>
<xsd:field xpath="@name"/>
</xsd:key>
对于第二个,我在元素声明中使用了这个:
<xsd:key name="partKey">
<xsd:selector xpath="part"/>
<xsd:field xpath="./@name"/>
</xsd:key>
现在可以了。
但是对于第三部分,我尝试将此代码放入(第一个共同祖先)但它不起作用:
<xsd:keyref name="roadSegmentRef" refer="roadSegmentKey">
<xsd:selector xpath="identifiedEntity/place/roadSegment" />
<xsd:field xpath="." />
</xsd:keyref>
但我得到的只是:
cvc-identity-constraint.4.3: Key 'partRef' with value 'A1' not found for identity constraint of element 'parent'. file.xml /sheet/xsd line 19 XML Problem
解决方案
你没有告诉我们你把这些声明放在哪里,我猜你把它们放在错误的地方。
如果您希望某个 Y 中的每个 X 都具有 Z 的唯一值,那么您的键/唯一声明需要进入 Y 的元素声明;选择器需要从Y开始选择X,字段需要从X开始选择Z。
推荐阅读
- r - 如何创建要传递给公式的用户定义样条实现
- python - 将数据从 jquery 成功填充到模态时出现问题
- swift - 所有按钮(圆形、三角形)都有一个矩形框作为点击区域
- macos - 如何在 shift + tab 上的终端中向后启用自动完成功能?
- ethereum - 如何测试由另一个已部署合约生成的合约?
- r - R中的Mapdist在传递坐标时返回错误
- sql - 如何处理在 DoCmd.RunSQL(INSERT INTO...) 之后找到的 0 行
- ansible - 从 stdout_lines 获取特定输出并将其存储在列表中
- mysql - 遇到 PHP 错误 严重性:通知消息:未定义的索引
- biztalk - BizTalk 2016 单例