首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSD Validaton keyref值找不到标识约束

XSD Validaton keyref值找不到标识约束
EN

Stack Overflow用户
提问于 2017-07-08 00:04:14
回答 1查看 1.2K关注 0票数 0

我在XSD验证方面遇到了一些问题,这应该很容易运行。以下是我的XML:

代码语言:javascript
复制
<Configuration>
    <Dependencies>
        <Dependency name="python"></Dependency>
    </Dependencies>
    <Plugins>
        <Plugin>
            <Dependencies>
                <Dependency name="python"></Dependency>
            </Dependencies>
        </Plugin>
    </Plugins>
</Configuration>

现在是我的架构(请不要在Configuration元素中使用key.keyref对):

代码语言:javascript
复制
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Configuration">
        <xs:complexType>
            <xs:sequence minOccurs="1" maxOccurs="1">
                <xs:element name="Dependencies" type="DependenciesType"></xs:element>
                <xs:element name="Plugins">
                    <xs:complexType>
                        <xs:sequence minOccurs="1" maxOccurs="unbounded">
                            <xs:element name="Plugin" type="PluginType" minOccurs="1" maxOccurs="unbounded"></xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>

        <xs:key name="kDependency">
            <xs:selector xpath="./Dependencies/Dependency"></xs:selector>
            <xs:field xpath="@name"></xs:field>
        </xs:key>
        <xs:keyref name="krPluginDependency" refer="kDependency">
            <xs:selector xpath="./Plugins/Plugin/Dependencies/Dependency"></xs:selector>
            <xs:field xpath="@name"></xs:field>
        </xs:keyref>

    </xs:element>

    <!-- Now the Dependencies types -->

    <xs:complexType name="DependenciesType">
        <xs:sequence>
            <xs:element minOccurs="1" maxOccurs="unbounded" name="Dependency" type="DependencyType"></xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="DependencyType">
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>

    <!-- And the plugin type -->

    <xs:complexType name="PluginType">
        <xs:sequence>
            <xs:element name="Dependencies" minOccurs="1" maxOccurs="1">
                <xs:complexType>
                    <xs:sequence minOccurs="1" maxOccurs="1">
                        <xs:element name="Dependency" minOccurs="1" maxOccurs="unbounded">
                            <xs:complexType>
                                <xs:attribute name="name"></xs:attribute>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

</xs:schema>

插件依赖项名称必须引用配置依赖项名称。我遵循这里的教程,以检查我是否是傻瓜(st5.html)。我检查了我的XPath表达式,它们很好(https://www.freeformatter.com/xpath-tester.html)。

当我试图验证我的XML文件时:

键'krPluginDependency‘和值'python’没有找到元素‘配置’的标识约束。

我不知道问题出在哪里。

EN

回答 1

Stack Overflow用户

发布于 2017-07-08 12:18:17

好吧,这真是个荒谬的错误。在PluginType Dependency类型中,属性name需要一个类型。在我的例子中,它是type="xs:string",工作正常。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44981203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档