[xml] XSD: key-keyref in recursive elements
- From: Cédric Coussinet <cedric coussinet nomoseed net>
- To: <xml gnome org>
- Subject: [xml] XSD: key-keyref in recursive elements
- Date: Thu, 27 Mar 2014 10:05:48 +0100
Hello,
On the XML schema validation in libxml2, I wonder about the behavior of key
(key / keyref).
The following example shows three ways to validate the uniqueness of an
attribute (in the example, necessarily unique because a single target
element). The difficulty lies in the recursive elements.
The first two key (valueUnique and valueKeyAlone) validate the document
while the last (valueKey / valueRef) indicates an error.
On Windows, I used the libxml2 2.7.8 and the version 2.9.1, same result :
xmllint.exe --noout schema test.xsd test.xml
Element '{http://www.test.org/test}B': More than one match found for
key-sequence ['1'] of keyref '{http://www.test.org/test}valueRef'.
test.xml fails to validate
test.xml
--------
<?xml version="1.0" encoding="UTF-8"?>
<A xmlns="http://www.test.org/test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<A>
<B value="1"/>
</A>
<B value="1"/>
</A>
test.xsd
--------
<?xml version="1.0" encoding="utf-8"?>
<schema attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://www.test.org/test"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://www.test.org/test">
<element name="A">
<complexType>
<sequence>
<element ref="test:A" minOccurs="0" maxOccurs="unbounded"/>
<element name="B" minOccurs="0" maxOccurs="unbounded">
<complexType>
<attribute name="value" type="integer" use="required"/>
</complexType>
</element>
</sequence>
</complexType>
<unique name="valueUnique">
<selector xpath="./test:B"/>
<field xpath="@value"/>
</unique>
<key name="valueKeyAlone">
<selector xpath="./test:B"/>
<field xpath="@value"/>
</key>
<key name="valueKey">
<selector xpath="./test:B"/>
<field xpath="@value"/>
</key>
<keyref name="valueRef" refer="test:valueKey">
<selector xpath="./test:B"/>
<field xpath="@value"/>
</keyref>
</element>
</schema>
Is this normal?
The answer in this discussion
(http://lists.w3.org/Archives/Public/xmlschema-dev/2005Sep/0057.html) is
still relevant?
Thanking you in advance,
Best regards,
Cédric Coussinet
http://www.nomoseed.org
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]