Reputation: 367
I've got some troubles with XSD keyref validation which should run easily. Here is my XML:
<Configuration>
<Dependencies>
<Dependency name="python"></Dependency>
</Dependencies>
<Plugins>
<Plugin>
<Dependencies>
<Dependency name="python"></Dependency>
</Dependencies>
</Plugin>
</Plugins>
</Configuration>
And now my Schema (please not the key.keyref pair in the Configuration element):
<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>
The plugin dependencies name has to refer to Configuration dependencies name. I followed the tutorial here in order to check if I am not fool (http://zvon.org/xxl/XMLSchemaTutorial/Output/ser_keys_st5.html). I checked my XPath expression and they are good (https://www.freeformatter.com/xpath-tester.html).
When I try to validate my XML file:
Key 'krPluginDependency' with value 'python' not found for identity constraint of element 'Configuration'.
I do not know where is the problem.
Upvotes: 0
Views: 1578
Reputation: 367
Okay, it was really ridiculous error.
In PluginType
Dependency
type, the attribute name
needs a type. In my case, it is type="xs:string"
and it works fine.
Upvotes: 1