AW: [xml] IDC bug?
- From: "Kasimier Buchcik" <k buchcik 4commerce de>
- To: "Frans Englich" <frans englich telia com>
- Cc: xml gnome org
- Subject: AW: [xml] IDC bug?
- Date: Thu, 6 Apr 2006 11:41:20 +0200
Hi,
-----Ursprüngliche Nachricht-----
Von: xml-bounces gnome org [mailto:xml-bounces gnome org] Im
Auftrag von Frans Englich
Gesendet: Mittwoch, 5. April 2006 17:24
An: xml gnome org
Betreff: [xml] IDC bug?
Either I'm not using IDCs correctly(which may very well be
the case), or
there's a bug in xmllint. Consider this schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="test-group">
<xs:complexType>
<xs:sequence>
<xs:element name="test-case" minOccurs="0"
maxOccurs="unbounded">
<xs:unique name="idc1">
<xs:selector xpath="."/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
<xs:element ref="test-group" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="name" type="xs:string"
use="required" />
</xs:complexType>
<xs:unique name="idc2">
<xs:selector xpath="."/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
The following two documents validates.
<test-group name="group1">
<test-group name="group1"/>
</test-group>
<test-group name="group1">
<test-case name="test-case1"/>
<test-case name="test-case1"/>
</test-group>
But as I see it, they shouldn't. Or should they?
This was produced with libxml2 version 20623.
The two documents you provided are valid (tested with
Saxon, Xerces and XSV).
I think a good way of understanding what's going on with
IDC key/unique is to imagine that a local list of values
(selected by the <xs:selector> and <xs:field>s) is built
on the element-node for which an IDC key/unique is declared;
after the validation is finished with such an element-node,
the local list disappears.
So for the <test-case>s we get:
<test-case name="test-case1"/> --> list with 1 entry: "test-case1"
<test-case name="test-case1"/> --> list with 1 entry: "test-case1"
Both lists are seperate from each other, so there's no error.
I think what you want, in order to disallow duplicate names for
the test-cases, is to declare the xs:unique on the test-group and
select all names of all test-case children:
<xs:unique name="idc2">
<xs:selector xpath="./test-case"/>
<xs:field xpath="@name"/>
</xs:unique>
This will generate a list on the test-group:
<test-group name="group1"> --> list with 2 entries:
<test-case name="test-case1"/> "test-case1"
<test-case name="test-case1"/> "test-case1"
</test-group>
And this will - with some processors - produce an error.
"With some processors", since there's a gray area in the spec:
Libxml2 won't report an error, since there's an other issue within
the schema. The element "test-case" doesn't specify a type, so
the type defaults to xs:anyType; an element of this type can
have any content and any attributes (lax attribute wildcard).
The spec is silent about the case when IDCs resolve to
non-declared elements/attributes.
In xmlschemas.c, xmlSchemaVAttributesComplex(), it reads:
"Only "assessed" attribute information items will be visible to
IDCs. I.e. not "lax" (without declaration) and "skip" wild attributes."
XSV 2.10-1 won't report an error as well.
On the other side Saxon 8.7 and Xerces-J 2.5.1 *do* report an error.
I think we should go the Saxon/Xerces way here. It would be great
if you could bugzilla this.
Possible workarounds:
1) declare the "name" attribute locally on "test-case"
2) declare a global attribute:
<xs:attribute name="name" type="xs:string"/>
The lax attribute wildcard of the xs:anyType will then pick
this global attribute declaration for the "name" attribute
of "test-case" and the IDCs will resolve to that attribute.
Your schema could look like the following. It additionally
has a "tests" element, acting as a container for test-groups
and test-cases, plus defining IDCs. Due to "//" in
the selector ".//test-group" it will assure unique names
for all test-groups in the document.
Schema "idc.xsd":
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test-case">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="test-group">
<xs:complexType>
<xs:sequence>
<xs:element ref="test-case" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="test-group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="tests">
<xs:complexType>
<xs:sequence>
<xs:element ref="test-case" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="test-group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="unique-test-group">
<xs:selector xpath=".//test-group"/>
<xs:field xpath="@name"/>
</xs:unique>
<xs:unique name="unique-test-case">
<xs:selector xpath=".//test-case"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
Instance "idc.xml":
<tests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="idc.xsd">
<test-case name="test-case1"/>
<test-case name="test-case1"/>
</tests>
xmllint --noout --schema idc.xsd idc.xml
idc.xml:7: element test-case: Schemas validity error :
Element 'test-case': Duplicate key-sequence ['test-case1'] in
unique identity-constraint 'unique-test-case'.
idc.xml fails to validate
Regards,
Kasimier
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]