Hi,
Eric van der Vlist's book XML Schema says that we can use xs:key to declare
co-occurrence constraints. The example he uses (boiled down a bit) is a
"book" element that must have either an "isbn" attribute or an "isbn" child
element, but not both:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://www.example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com"
elementFormDefault="qualified">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="isbn" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>
<xs:key name="dummy">
<xs:selector xpath="."/>
<xs:field xpath="isbn|@isbn"/>
</xs:key>
</xs:element>
</xs:schema>
Now, if the isbn attribute (only) is present, it validates fine. But if the
isbn child (only) is present, I get the following validation error:
The identity constraint 'http://www.example.com:dummy' validation has failed
due to either a key is missing or the exsisting key has an empty node.
And if both the attribute and child are present, I get no validation error
(which is wrong).
I am using Visual Studio .NET, hence the .NET Framework version 1.0. Am I
experiencing a limitation in Microsoft's support for XML Schema, or am I
missing something? Any insights appreciated!
Eric W. Sirko