472,958 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2798
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.