密钥和密钥引用验证

密钥和密钥引用验证

本文介绍了XSD:密钥和密钥引用验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模式验证方面遇到问题,这是我的

Bookmark 中的 ID 元素应该是键,并且收藏夹/文件夹/书签/书签 ID 属性应该总是引用一个书签 ID.

这是我的 xsd:

解决方案

键的上下文是 元素,因为在架构中它们是 < 的子元素;xs:element name="root"> 元素.因此,您的 XPath 失败,因为它们以 root/... 开头,它不是 的子级代码>元素.为 keykeyref 删除它.由于类似的问题,密钥的 也失败了.您已经选择 元素作为上下文,然后尝试为该元素查找 子元素.将 的 XPath 切换为 .(一个点)或从选择器中删除尾随的 /ID.>

这是一个有效的代码示例.

<xs:complexType><xs:序列><xs:element name="Favorites" type="Favorites"/><xs:element name="Bookmarks" type="Bookmarks"/></xs:sequence></xs:complexType><xs:keyref name="bookmarkIDKeyRef"refer="bookmarkIDKey"><xs:selector xpath="收藏夹/文件夹/书签/*"/><xs:field xpath="@ID"/></xs:keyref><xs:key name="bookmarkIDKey"><xs:selector xpath="书签/书签"/><xs:field xpath="ID"/></xs:key></xs:element>

I'm having issues with schema validation, this is my

<?

The ID element in Bookmark should be the key, and the Favorites/Folder/Bookmarks/Bookmark ID attribute should always reference a Bookmark ID.

Here is my xsd:

<?

The

解决方案

The context of your keys is the <root> element, because in the schema they are children of the <xs:element name="root"> element. Therefore your <xs:selector> XPaths fail, because they begin with root/... which is not a child of the <root> element. Drop it for both key and keyref. Also the <xs:field> of the key fails due to similar issue. You already select the <ID> element as the context and then try to look for an <ID> child for this element. Switch the XPath of the <xs:field> to . (a dot) or drop the trailing /ID from the selector.

Here is a working code sample.

<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Favorites" type="Favorites"/>
            <xs:element name="Bookmarks" type="Bookmarks"/>
        </xs:sequence>
    </xs:complexType>
    <xs:keyref name="bookmarkIDKeyRef" refer="bookmarkIDKey">
        <xs:selector xpath="Favorites/Folder/Bookmarks/*"/>
        <xs:field xpath="@ID"/>
    </xs:keyref>
    <xs:key name="bookmarkIDKey">
        <xs:selector xpath="Bookmarks/Bookmark"/>
        <xs:field xpath="ID"/>
    </xs:key>
</xs:element>

这篇关于XSD:密钥和密钥引用验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:02