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

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 2731


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*******@yahoo.de> wrote in message news:<41***********************@newsread2.arcor-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
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....
13
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...
4
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...
3
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...
3
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...
5
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...
1
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...
5
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...
3
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? ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.