473,785 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSD question - relationship between attributes?

Hey All -

I'm stuck while trying to write a schema, hoping someone can provide me
with a flash of inspiration.

One of the elements I'm writing has two attributes, both of which are
optional. I want to express in the schema that there's a relationship
between the two -- that the second attribute is optional only if the
first one is not specified. ie:

<myElement /> <!-- valid -->
<myElement name="A" /> <!-- valid -->
<myElement myattr="true" /> <!-- invalid because name wasn't specified
-->
<myElement myattr="true" name="A" /> <!-- valid -->

So far my schema looks like this:

<element name="myElement ">
<complexType>
<attribute name="name" type="string" use="optional" />
<attribute name="myattr" type="boolean" use="optional"
default="false" />
</complexType>
</element>
That captures the default values and the optional nature of the two
elements, but it doesn't capture the relationship between the two. Is
there any xsd construct I can use to express the relationship? I know
how to do it with elements (xsd:group, xsd:choice) but not with
attributes.

Thanks for any thoughts.

Stewart

Jul 20 '05 #1
2 2760


Stewart Johnson wrote:

I'm stuck while trying to write a schema, hoping someone can provide me
with a flash of inspiration.

One of the elements I'm writing has two attributes, both of which are
optional. I want to express in the schema that there's a relationship
between the two -- that the second attribute is optional only if the
first one is not specified. ie:

<myElement /> <!-- valid -->
<myElement name="A" /> <!-- valid -->
<myElement myattr="true" /> <!-- invalid because name wasn't specified
-->
<myElement myattr="true" name="A" /> <!-- valid -->

So far my schema looks like this:

<element name="myElement ">
<complexType>
<attribute name="name" type="string" use="optional" />
<attribute name="myattr" type="boolean" use="optional"
default="false" />
</complexType>
</element>
That captures the default values and the optional nature of the two
elements, but it doesn't capture the relationship between the two. Is
there any xsd construct I can use to express the relationship? I know
how to do it with elements (xsd:group, xsd:choice) but not with
attributes.


I don't think that a W3C XML schema can express such constraints between
attributes. Other schema languages are more powerful in that regard, for
instance schematron should allow that.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Martin Honnen <ma*******@yaho o.de> wrote in message news:<41******* *************** *@newsread2.arc or-online.net>...
Stewart Johnson wrote:

I'm stuck while trying to write a schema, hoping someone can provide me
with a flash of inspiration.

One of the elements I'm writing has two attributes, both of which are
optional. I want to express in the schema that there's a relationship
between the two -- that the second attribute is optional only if the
first one is not specified. ie:

<myElement /> <!-- valid -->
<myElement name="A" /> <!-- valid -->
<myElement myattr="true" /> <!-- invalid because name wasn't specified
-->
<myElement myattr="true" name="A" /> <!-- valid -->

So far my schema looks like this:

<element name="myElement ">
<complexType>
<attribute name="name" type="string" use="optional" />
<attribute name="myattr" type="boolean" use="optional"
default="false" />
</complexType>
</element>
That captures the default values and the optional nature of the two
elements, but it doesn't capture the relationship between the two. Is
there any xsd construct I can use to express the relationship? I know
how to do it with elements (xsd:group, xsd:choice) but not with
attributes.


I don't think that a W3C XML schema can express such constraints between
attributes. Other schema languages are more powerful in that regard, for
instance schematron should allow that.


Hi,

I don't think you can do it using attributes. But you can express it
using elements : use a <xs:choice> within a <xs:sequence>
Jul 20 '05 #3

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

Similar topics

28
2214
by: Jeff Lanfield | last post by:
Suppose I have users that can belong to organizations. Organizations are arranged in a tree. Each organization has only one parent organization but a user maybe a member of multiple organizations. The problem that I'm facing that both organizations and individual users may have relationships with other entities which are semantically the same. For instance, an individual user can purchase things and so can an organization. An individual...
13
1699
by: Tom | last post by:
Hi, Do you guys know what's wrong with a one-to-one relationship? The reason I want to make it like this is that at the very end of the chain, the set of keys is huge. I want to limit the number of columns to be the key. i.e. the table has 1 column as the key. The table will have 2 columns as the key.
4
6014
by: Melissa | last post by:
I have a frontend file named CustomerApp and backend file named CustomerData. CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer Database. Could someone help me with the code to do the following: 1. Create a new table named TblCustomerContact in CustomerData 2. Add a field named CustomerContactID (autonumber) in TblCustomerContact 3. Add a field named CustomerID (Number-Long) in TblCustomerContact 4. Add a field...
3
1622
by: Mason | last post by:
I have a table consisting of people and their attributes. I would like to create a relationship matrix table that records the relationships between the people. So the two tables would look something like this: tblPeople *ID, AutoNumber LastName, Text FirstName, Text
3
4686
by: MDS | last post by:
All, I would like to implement a recursive relationship in a table with referential integrity enforced and cascade update turned on. For example, a horse has a sire and dam. Both the sire and the dam must be horses and, therefore, drawn from the same domain. Is it possible to implement this recursive relationship in Access 97 having "Sire" and "Dam" attributes in the "Horse" table?
5
2396
by: BrianDP | last post by:
This is a strange one-- I have an Access 2K database with a split front end/back end. There are two tables in the back end - RFile and RLine. There is a one to many relationship from Rfile.Rnumber to Rline.Rnumber. Originally I went in with the Relationships window, drew the line, and clicked the cascading updates and deletes. Everything was fine, for a couple of years. All of the sudden however, this relationship seems to delete...
1
2008
by: JavaXMLDev | last post by:
Hi I'm new to XML schema work, but wondered how, if at all possible, can you specify a relationship between the values of an element's attributes. Essentially I want context sensitive auto-complete for the attribute values of an element when creating an XML document. I dont know how to define the relationship ! Scenario: When using a location element and selecting the school value for the type attribute I would like to restrict...
5
4998
by: Yitzak | last post by:
Hi after adding a field to a table through VBA How do I create a foreign key constraint/relationship between this field and a field in another table - and enforce referential integrity through VBA code. Thanks
3
1051
by: King | last post by:
This is a new test for object persistency. I am trying to store the relationship between instances externally. It's not working as expected. May be I am doing it in wrong way. Any suggestions? import shelve class attrib(object): pass
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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
10148
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
10091
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
8972
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
7499
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
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2879
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.