473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XSD Schema - nillable fields in keyref

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>

Jan 26 '06 #1
2 2826
Hi,

I don't think there's anything in the XML Schema rec that says to treat
nilled elements any differently than empty elements when it comes to
resolving keyrefs, so I think this is an error.

The workaround would be to omit the Owner element if it's not applicable.
Alternatively, you could insert a dummy Person element with an empty value
in the ID attribute, but that seems klugey.

Hope that helps,
Priscilla

------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

<sv*****@bigfoot.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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>

Jan 27 '06 #2
Thanks for the quick answer!

<xs:element name="Owner" type="xs:string" minOccurs="0"/>

seems to be the way to go.

Regards
/Stefan

Jan 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Olaf Meyer | last post by:
I'm wondering if I can also express uniquness constraints on attributes of objects that I have referenced from somewhere else. To be a bit more precise here a short and simple XML document. The...
0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named...
5
by: Harald Haspl | last post by:
Hello, I've appended a simple XML file and it's appropriate schema below. I want to validate the XML file against the schema with xerces-c. This example contains a section where colours are...
2
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
2
by: Mike | last post by:
Hi! I have an Excel 2003 Schema I need to parse to extract elements names. I am puzzled which System.Xml object can help me. Here's the example of my schema: I need to get a collection of...
1
by: Mike | last post by:
Hi! I have an Excel 2003 Schema I need to parse to extract elements names. I am puzzled with the System.Xml.Schema object. Here's the example of my schema: I need to get a collection of element...
1
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i...
2
by: bmichel | last post by:
Regarding the XSD schema shown below, I want to modifiy it so that: - the "owner_id" attribute in the "dog" element to exist in one of the "owner" element "id" attribute. - the "id" attribute in...
2
by: pnmcosta | last post by:
Hi, I'm fairly new to XML Schema validation. We have XML being imported that must validate against the following schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.