У меня есть важная проблема с XSD, XML, XPath и так далее.XML Keyref со значением «null»
Вот мой XML-файл:
<?xml version="1.0" encoding="utf-8"?>
<biblioteka xmlns:aw="http://www.w3.org/2001/XMLSchema-instance" aw:noNamespaceSchemaLocation="schema.xsd">
<gatunek>
<identyfikator id="fan"/>
</gatunek>
<dział>
<książka gatunek_id="fan"/>
</dział>
</biblioteka>
И это schema.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="biblioteka" type="moja_biblioteka">
<xs:unique name="IDUnique">
<xs:selector xpath="gatunek/identyfikator"/>
<xs:field xpath="@id"/>
</xs:unique>
<xs:keyref name="gatunekIDKeyRef" refer="IDUnique">
<xs:selector xpath="dział/książka"/>
<xs:field xpath="@gatunek_id" />
</xs:keyref>
</xs:element>
<xs:complexType name="moja_biblioteka">
<xs:sequence>
<xs:element ref="gatunek"/>
<xs:element ref="dział" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="gatunek">
<xs:complexType>
<xs:sequence>
<xs:element name="identyfikator" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="dział">
<xs:complexType>
<xs:sequence>
<xs:element name="książka" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="książka">
<xs:complexType>
<xs:attribute name="gatunek_id" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]{3,6}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Все вроде бы хорошо, но это не так: /. Когда я проверяю это (я использую NetBeans), я получаю это сообщение об ошибке:
Ключ 'gatunekIDKeyRef' со значением 'null' не найден для ограничения личности элемента 'biblioteka'. [10]
Я борюсь с ними в течение нескольких часов, другие решения, которые я нашел в stackoverflow, не помогают мне.
Спасибо, ваше решение решило мою проблему. Я бы никогда не нашел это в одиночку: D –