【问题标题】:XSD Validaton keyref value not found for identity constraintXSD Validaton keyref value not found for identity constraint
【发布时间】:2017-07-08 20:18:17
【问题描述】:

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

<Configuration>
    <Dependencies>
        <Dependency name="python"></Dependency>
    </Dependencies>
    <Plugins>
        <Plugin>
            <Dependencies>
                <Dependency name="python"></Dependency>
            </Dependencies>
        </Plugin>
    </Plugins>
</Configuration>

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

<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>

插件依赖名必须参考配置依赖名。我按照这里的教程来检查我是否不是傻瓜(http://zvon.org/xxl/XMLSchemaTutorial/Output/ser_keys_st5.html)。我检查了我的 XPath 表达式,它们很好 (https://www.freeformatter.com/xpath-tester.html)。

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

没有为元素“配置”的标识约束找到值为“python”的键“krPluginDependency”。

我不知道问题出在哪里。

【问题讨论】:

  • 我试图重现该问题,但您的 XML 文件可以针对 oXygen 19 中的架构进行良好验证。您可能需要添加有关您在收到错误时使用的工具/解析器的详细信息。
  • 我在网上使用了这样的验证器 (freeformatter.com/xml-validator-xsd.html) 或这个 (utilities-online.info/xsdvalidation) 但现在你提到它可以是使用的工具,一些在线工具是由 JAXB 引擎驱动的,这并不是真的支持一些 keyrefs 案例。我将尝试在 python 中使用 lxml。

标签: xml xpath xsd keyref


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    相关资源
    最近更新 更多