473,507 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uniqueness only for some attribute value

Hi,

I want to add uniqueness constraint for an attribute, but only for a
certain value, for example, the attribute can be 'true' or 'false' or
none, I want to allow only one 'true' value. How should I do? I tried
to use like this:
<xs:key name="attributeKey">
<xs:selector xpath="./MyElement[@myAttribute = 'true']"/>
<xs:field xpath="@myAttribute"/>
</xs:key>

but this gives validation error in xsd.
Any help is appreciated.

Thanks.
Nov 12 '05 #1
3 1390
kate wrote:
I want to add uniqueness constraint for an attribute, but only for a
certain value, for example, the attribute can be 'true' or 'false' or
none, I want to allow only one 'true' value. How should I do? I tried
to use like this:
<xs:key name="attributeKey">
<xs:selector xpath="./MyElement[@myAttribute = 'true']"/>
<xs:field xpath="@myAttribute"/>
</xs:key>


AFAIK XSD doesn't allow that. It only supports very limited subset of XPath.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
> AFAIK XSD doesn't allow that. It only supports very limited subset of XPath.

Thanks for reply.

And do you know how I can use conditions in xsd? For example, I would
like to restrict some element or attribute under a certain condition,
like when an attribute is some value. Thanks in advance.
Nov 12 '05 #3
kate wrote:
And do you know how I can use conditions in xsd? For example, I would
like to restrict some element or attribute under a certain condition,
like when an attribute is some value. Thanks in advance.


I'm afraid it's the same anser - you cannot. XSD Schema doesn't support
co-occurence constraints. Try different schema language (such as
schematron or relaxng) to validate such constraints.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #4

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

Similar topics

1
2955
by: Puvendran Selvaratnam | last post by:
Hi, First of all my apologies if you have seen this mail already but I am re-sending as there were some initial problems. This query is related to defining indexes to be unique or not and...
0
1552
by: Ognen Ivanovski | last post by:
Is the following constraint possible to be expressed with XML Schema (and how): Suppose we have a document in the form <car type="ford"> <part name="door"/> <part name="ashtray"/> </car>
0
1495
by: Don Bate | last post by:
I'm having a problem with the "unique" feature of XML Schema. I'm relatively new to using this feature so it may be that I'm misunderstanding something. Let's assume that I have the following...
0
1616
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...
2
2141
by: Dirk Declercq | last post by:
Hi, Is it possible in Xml to enfore the uniqueness of an element based on his attribute value. Say I have this schema : <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
1
1551
by: Mr. Almenares | last post by:
Hello: I’m trying to do a schema with recurrent structure for a Book like a Node can have many Nodes inside or One leave. So, the leaves have an attribute that is Identifier. My goal is define...
4
4176
by: wendy | last post by:
Just curious to know if there is a simple way to ensure uniqueness among non-null values within a nullable column. For instance if I have a column of Names that can contain null values, I would...
1
1426
by: Lemon Tree | last post by:
Hello everybody. I would like to set an uniqueness constraint by checking more than one attribute. So: .... <foo a1="a" a2="a"/> <foo a1="a" a2="b"/> <foo a1="a" a2="c"/>
8
1904
by: gnomff | last post by:
Hi, I'm new to creating schemas, and I would like to make an attribute unique. What I currently have looks like this: <xs:element name="Tick" type="TickType" maxOccurs="unbounded"...
0
7111
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
7319
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,...
1
7031
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...
0
7485
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...
0
5623
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,...
0
4702
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
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 ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.