473,769 Members | 6,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 <locationInstan ce> 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 1766


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 <locationInstan ce> 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 <locationInstan ce> 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="ImportDat a">
<xsd:complexTyp e>
<xsd:sequence >
.. definitions of the "locationTy pe" and "location" elements ..
</xsd:sequence>
</xsd:complexType >

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

<xsd:key name="locationI d">
<xsd:annotation >
<xsd:documentat ion>Within the whole data set, every location
must have a unique ID attribute</xsd:documentati on>
</xsd:annotation>
<xsd:selector xpath=".//location"/>
<xsd:field xpath="@id"/>
</xsd:key>

<xsd:keyref name="locationI dRef" refer="location TypeId">
<xsd:annotation >
<xsd:documentat ion>Locations must be of an existing
locationType</xsd:documentati on>
</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
2395
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 generate any of the specific instances. sample schema one: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="base">
1
1372
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 entry elements in it. but this x value needs to be hardcoded in the schema.
0
1727
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" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Loan"> <xs:complexType> <xs:sequence> <xs:element name="Borrower" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="BorrID" use="required">
2
9236
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" encoding="utf-8"?> <Book ID="1000000000"> <Name>XML Basic</Name> <Comments>Whatever</Comments>
1
3972
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 names." "When SQL Server looks up a table/view without a schema qualification, it first searches the default schema and then the 'dbo' schema. The default schema corresponds to the current user for ad-hoc batches, and corresponds to the schema...
0
1330
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 content. To make the parts unique, the top-level element of the further content
1
2209
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 example. Any ideas? A stripped down schema segment is shown below: <xs:complexType name="condition">
3
1677
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" age="25"/> In my schema, I'd love to be able to place different restrictions on the attribute 'age' based on the value of 'name'... so in this example, I might want to enforce that any entry where name="John"
0
1535
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 all the instances at the same time, this leads into inconsistent of DB schema. My question, is there any tool/script that can sync all my DB instances automatically once i upgrade one instance.(Sync only at schema level not data). I have heard...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.