The workaround would be to omit the Owner element if it's not applicable.
<svestin@bigfoot.com> wrote in message
news:1138288158.322462.292660@g44g2000cwa.googlegroups.com...
> Hi All!
>
> I run into a problem defining a XSD schema with KEYREF references.
>
> Is it possible to use KEYREF with nillable fields?
> Just like a database where a FK could be null.
>
> In the example below the tag <Owner> is nillable
> and also used as FIELD in the KEYREF.
>
> Run this in Visual Studio 2005 XML Editor and there will be NO error.
> Run this in XMLSpy and there WILL BE an error.
>
> Anyone out there with any suggestions or workarounds?
>
> Regards
> /Stefan Vestin
>
>
>
> <== FILENAME=KeyRef.xml ==>
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="testNS KeyRef.xsd" xmlns="testNS">
>
> <Persons>
> <Person ID="123">
> <Name>John</Name>
> </Person>
> <Person ID="456">
> <Name>Frank</Name>
> </Person>
> </Persons>
>
> <Vehicles>
> <Vehicle ID="ABC">
> <Owner xsi:nil="true"></Owner> <=== Reference that is NULL
> </Vehicle>
> </Vehicles>
>
> </root>
>
>
> <== FILENAME=KeyRef.xsd ==>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema" xmlns:t="testNS"
> targetNamespace="testNS" elementFormDefault="qualified"
>
> attributeFormDefault="unqualified">
> <xs:element name="root">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Persons">
> <xs:complexType>
> <xs:sequence maxOccurs="unbounded">
> <xs:element name="Person">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Name" type="xs:string"/>
> </xs:sequence>
> <xs:attribute name="ID" type="xs:string"/>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="Vehicles">
> <xs:complexType>
> <xs:sequence maxOccurs="unbounded">
> <xs:element name="Vehicle">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="Owner" type="xs:string"
> nillable="true"/>
> </xs:sequence>
> <xs:attribute name="ID" type="xs:string"/>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
>
> <xs:key name="PersonKey">
> <xs:selector xpath=".//t:Person"/>
> <xs:field xpath="@ID"/>
> </xs:key>
>
> <xs:keyref name="OwnerRef" refer="t:PersonKey">
> <xs:selector xpath=".//t:Vehicle"/>
> <xs:field xpath="t:Owner"/>
> </xs:keyref>
>
> </xs:element>
> </xs:schema>
>