473,661 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML schema uniqueness constraints

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
"objects" have a key constraint on the id attribute, i.e. they need to
be unique. The object-ref element may reference the previously defined
objects and hence has a keyref constraint on the id attribute.

I would now like to furhter restrict the object-ref elements by only
allowing refrerences, such that the class attributes of the referred
objects are unique. Is there an elegant way to do this via a XML
uniquness constraint?

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.mynames.org "
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocat ion="http://www.mynames.org
x:/work/sjrodc/xml/constraint.xsd" >
<my-objects>
<object id="1" class="Car"/>
<object id="2" class="Car"/>
<object id="3" class="Bike"/>
</my-objects>
<object-ref id="1"/>
<!-- How can I specify a constraint in the schema such that only
objects with distinct classes can be referenced?
i.e. only one of the objects with id 1 or 2 can be
selected -->
<!-- this should cause a constraint violation -->
<object-ref id="2"/>

<object-ref id="3"/>
</root>

I already have a schema file that has a key constraint on the objects id
attribute and a keyref constraint on the object-ref id attribute. Is it
possible to add another constraint to get the above behavior?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace ="http://www.mynames.org "
xmlns:mf="http://www.mynames.org "
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.mynames.org " elementFormDefa ult="qualified" >
<xs:element name="root">
<xs:complexTy pe name="">
<xs:sequence>
<xs:element name="my-objects">
<xs:complexType >
<xs:sequence>
<xs:element name="object"
maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="id"
use="required"/>
<xs:attribute name="class"
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="object-ref" maxOccurs="unbo unded">
<xs:complexType >
<xs:attribute name="id"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

<!-- here are the constraints -->
<xs:key name="objectIdK ey">
<xs:selector xpath=".//mf:object"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="objectRef " refer="objectId Key">
<xs:selector xpath=".//mf:object-ref"/>
<xs:field xpath="@id"/>
</xs:keyref>
<xs:unique name="classUniq ue">
<xs:selector xpath=".//mf:object"/>
<xs:field xpath="@id"/>
</xs:unique>

</xs:element>
</xs:schema>
Thanks,
Olaf
Jul 20 '05 #1
0 1623

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

Similar topics

1
2963
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 consequences thereof. Some documented facts that I am aware of include
2
4655
by: Olaf Meyer | last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints specified in the schema (e.g. constraints specified via unique element). The validation works with the XML editor I'm using (XMLSpy4) but not with Xerces 2.6.0. I've included a really short and simple example to illustrate it. I would like to get some comments on the validation capabilities of Xerces 2.6.0. I though it *fully* supported W3C Schema!
3
2300
by: Victor | last post by:
Hi, I have some sample XML and an XSD below I have written. The XSD almost does what I want. What I need is some way of enforcing that AT LEAST TWO of the attributes "TestAttribute" are "X". Can this be done and if so how? Thank you Victor
3
1860
by: Victor Engmark | last post by:
How do I define that the contents of an element should be unique only in a sub-tree of the whole XML file? In my case, I have several documents, each containing several files. The file names have to be unique only within each document. I.e., the following is valid: <doc> <file>AAA</file> <file>BBB</file> </doc>
1
1562
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 Uniqueness that guarantees to the attribute Identifier his uniqueness. That I don’t know the depth of levels I have to put in the xpath attribute of the selector something like this TOC/descendant::Tree/Data, but this is not allow. How I can...
7
7377
by: Robert Stearns | last post by:
I ran the following bit of SQL and my PRIMARY KEY wound up in schema SYSIBM called SQL.... not schema is3 called primary. The index registation did wind up there. Obviously there's something I don't understand or see. If you have some insight into this problem that you are willing to share, I'd be grateful. One possibility is the uniqueness required: is the constraint required to be unique with table, schema or database? PS: Ignore the...
2
2247
by: Frosty | last post by:
Howto make datagrid enforce rules of xml schema? Created xml schema in the designer. Constraints created there using the following <xs:simpleType name="zipcode"><xs:restriction base="xs:string"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType Datagrid does not enforce this rule, even though dataGrid1_Validating() is called. dataset.WriteXml() saves withouth any warning, but
3
1346
by: Mr Flibble | last post by:
Here is some highly imaginative XML I've constructed to highlight what it is I'm trying to achieve. (Seems easier with an example). <foobars> <foo> <bar x="dog" colour="brown"/> <bar x="cat" colour="grey"/> <bar x="fish" colour="gold"/> </foo> <foo>
13
1905
by: Martin Z | last post by:
I'm making a CRUD screen for an Oracle database... but problem is that the primary key in that table is populated via an autonumber, which in Oracle is done just with triggers and sequences. Suffice to say that ADO.Net 1.1 is unaware that this column is, despite appearances, optional - which is a problem when creating new rows. I was wondering what the best way to remove the constraint is? I've been bitten too many times by assuming the...
0
8432
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
8855
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...
1
8545
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
8633
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
7364
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...
0
5653
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();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
2
1986
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.