473,388 Members | 1,340 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,388 software developers and data experts.

Schema restrictions on objects and instances

I have a Schema with some elements which are "types" or objects, and
some elements which correspond to instances of the types. How can I
specify that a <locationInstance> must have an attribute "type" which
equals any one of the "id" attributes of the <locationType>s?

--
Victor
CERN / NTNU
Jul 20 '05 #1
2 1749


Victor wrote:
I have a Schema with some elements which are "types" or objects, and
some elements which correspond to instances of the types. How can I
specify that a <locationInstance> must have an attribute "type" which
equals any one of the "id" attributes of the <locationType>s?


Have a look at ID/IDREF and key/keyref.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote:


Victor wrote:
I have a Schema with some elements which are "types" or objects, and
some elements which correspond to instances of the types. How can I
specify that a <locationInstance> must have an attribute "type" which
equals any one of the "id" attributes of the <locationType>s?

Have a look at ID/IDREF and key/keyref.


Thanks!

After a lot of looking around for working and well-explained examples, I
managed to get the following (in case someone is looking for something
similar):

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="ImportData">
<xsd:complexType>
<xsd:sequence>
.. definitions of the "locationType" and "location" elements ..
</xsd:sequence>
</xsd:complexType>

<xsd:key name="locationTypeId">
<xsd:annotation>
<xsd:documentation>Within the whole data set, every location
type must have a unique ID attribute</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//locationType"/>
<xsd:field xpath="@id"/>
</xsd:key>

<xsd:key name="locationId">
<xsd:annotation>
<xsd:documentation>Within the whole data set, every location
must have a unique ID attribute</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//location"/>
<xsd:field xpath="@id"/>
</xsd:key>

<xsd:keyref name="locationIdRef" refer="locationTypeId">
<xsd:annotation>
<xsd:documentation>Locations must be of an existing
locationType</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath=".//location"/>
<xsd:field xpath="@type"/>
</xsd:keyref>

.... The rest of the Schema ...

A few notes:

- <key> is basically the same as <unique>, except that the elements
and/or attributes referenced in the <field> XPath _has_ to exist, i.e.
they cannot be empty.

--
Victor
Jul 20 '05 #3

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

Similar topics

4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
1
by: obsolete_5 | last post by:
is it possible? more specifically, a simple example: i want a 'table' element to have a sequence of 'entry' elements. i know you can use minOccur = maxOccur = x, to enforce table to have x...
0
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: Shailendra Batham | last post by:
Hello Gurus, I want to put some restrictions on my attribute tag in my XML Schema, anyone out there have any idea how to do that. here is my XML and the XML Schema <?xml version="1.0"...
1
by: serge | last post by:
SQL BPA says the following: "One or more objects are referencing tables/views without specifying a schema! Performance and predictability of the application may be improved by specifying schema...
0
by: ruediger | last post by:
Hi there, I want to set up an XML Schema for documents of the following structure: The <root> node contains - an optional <message> element with a text attribute, and - arbitrary further...
1
by: Robert Mago | last post by:
I have an xml document instance in C# which loads an xml schema. I would like to load the restrictions for a complex type in the schema so that the user will choose one, from a drop down list for...
3
by: Marc Hebert | last post by:
I'm trying to figure out if something is possible to specify and constrain using a schema. I'll explain using an example. sample xml: <person name="John" age="32"/> <person name="Julie"...
0
by: idealfellow | last post by:
Hi Guys, I have multiple Mysql DB instances containing same schema but different data in the tables, running in my unix server. I always have the issue of not upgrading...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...

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.