我的 .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