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

Uniqueness based on Attribute-value

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 targetNamespace="http://www.egemin.com/Epia/StringResources"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.egemin.com/Epia/StringResources"
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="StrResources" type="StrResourcesType"/>

<xs:attribute name="LanguageAttr">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="nl"/>
<xs:enumeration value="nl-BE"/>
<xs:enumeration value="nl-NL/">
</xs:restriction>
</xs:simpleType>
</xs:attribute>

<xs:complexType name="StrResourcesType">
<xs:sequence>
<xs:element name="StrRes" type="StrResType" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="StrResType">
<xs:sequence>
<xs:element name="Tag" type="xs:ID"/>
<xs:element name="NeutrVal" type="StrValType"/>
<xs:element name="Localized" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Val" type="StrValType"/>
</xs:sequence>
<xs:attribute ref="LanguageAttr" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

</xs:schema>

And I have the following xml :

<?xml version="1.0" encoding="UTF-8"?>
<EPIA:StrResources xmlns:EPIA="http://www.egemin.com/Epia/StringResources"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.egemin.com/Epia/StringResources
StringResources.xsd">
<EPIA:StrRes>
<EPIA:Tag>
Egemin.EPIA.BaseContext.Context
</EPIA:Tag>
<EPIA:NeutrVal>Context</EPIA:NeutrVal>
<EPIA:Localized EPIA:LanguageAttr="nl"> <===
<EPIA:Val>Context</EPIA:Val>
</EPIA:Localized>
<EPIA:Localized EPIA:LanguageAttr="nl"> <===
<EPIA:Val>Contexte</EPIA:Val>
</EPIA:Localized>
</EPIA:StrRes>
</EPIA:StrResources>

How can I enfore that it is not allowed to have the attribute-val "nl" twice
in the same <EPIA:StrRes>-element ?


Nov 12 '05 #1
2 2132
Dirk Declercq wrote:
Is it possible in Xml to enfore the uniqueness of an element based on his
attribute value.
Sure. Make sure you've read XML Schema Primer on the topic:
http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness

This schema should be a bit modified to be able to express uniqueness
constraints. Uniqueness in schema relies on XPath patterns and XPath
doesn't support default namespace, which is your schema is based on. So
additionally declare prefix for your namespace:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.egemin.com/Epia/StringResources"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.egemin.com/Epia/StringResources"
elementFormDefault="qualified" attributeFormDefault="unqualified"


xmlns:EPIA="http://www.egemin.com/Epia/StringResources">

And now you can apply uniqueness constraint on StrRes element:

<xs:complexType name="StrResourcesType">
<xs:sequence>
<xs:element name="StrRes" type="StrResType" minOccurs="0"
maxOccurs="unbounded">
<xs:unique name="LocalazedUnique">
<xs:selector xpath="EPIA:Localized"/>
<xs:field xpath="@EPIA:LanguageAttr"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2
Tanks for the information.

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Dirk Declercq wrote:
Is it possible in Xml to enfore the uniqueness of an element based on his attribute value.


Sure. Make sure you've read XML Schema Primer on the topic:
http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness

This schema should be a bit modified to be able to express uniqueness
constraints. Uniqueness in schema relies on XPath patterns and XPath
doesn't support default namespace, which is your schema is based on. So
additionally declare prefix for your namespace:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.egemin.com/Epia/StringResources"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.egemin.com/Epia/StringResources"
elementFormDefault="qualified" attributeFormDefault="unqualified"


xmlns:EPIA="http://www.egemin.com/Epia/StringResources">

And now you can apply uniqueness constraint on StrRes element:

<xs:complexType name="StrResourcesType">
<xs:sequence>
<xs:element name="StrRes" type="StrResType" minOccurs="0"
maxOccurs="unbounded">
<xs:unique name="LocalazedUnique">
<xs:selector xpath="EPIA:Localized"/>
<xs:field xpath="@EPIA:LanguageAttr"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3

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

Similar topics

1
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
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
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
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...
1
by: Robert Ludewig | last post by:
<LinkList> <Link ID="A01" /> <Link ID="A02" /> <Link ID="A03" /> <Link ID="A01" /> </LinkList> How can I specify in a xmlschema that in the linklist are no occurences with same ID ? (Last...
1
by: Robert Ludewig | last post by:
<LinkList> <Link ID="A01" /> <Link ID="A02" /> <Link ID="A03" /> <Link ID="A01" /> </LinkList> How can I specify in a xmlschema that in the linklist are no occurences with same ID ? (Last...
1
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...
1
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"/>
5
by: Alan Little | last post by:
I have affiliates submitting batches of anywhere from 10 to several hundred orders. Each order in the batch must include an order ID, originated by the affiliate, which must be unique across all...
8
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.