Значение ключевой ссылки XSD Validaton не найдено для ограничения идентичности

У меня есть некоторые проблемы с проверкой ключей XSD, которые должны выполняться легко. Вот мой XML:

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

А теперь моя схема (пожалуйста, не указывайте пару key.keyref в элементе Configuration):

<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-файл:

Ключ 'krPluginDependency' со значением 'python' не найден для ограничения идентичности элемента 'Configuration'.

Я не знаю, где проблема.

1 ответ

Ладно, это была действительно нелепая ошибка. В PluginTypeDependency тип, атрибут name нужен тип. В моем случае это type="xs:string" и работает нормально.

Другие вопросы по тегам