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

Home Posts Topics Members FAQ

xsd:unique issue

2 New Member
Hi All,

I have the following XSD where my "number" is having unique constarint

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefa ult="qualified" >
<xs:element name="root">
<xs:complexType >
<xs:sequence>
<xs:element ref="number"/>
<xs:element ref="digit"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="number" type="xs:intege r">
<xs:unique name="numberUni que">
<xs:selector xpath="number"> </xs:selector>
<xs:field xpath="."></xs:field>
</xs:unique>
</xs:element>
<xs:element name="digit" type="xs:intege r"/>
</xs:schema>

My corresponding XML is like below

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "Unique.xsd ">
<number> 2</number>
<digit>2</digit>
</root>

As i understand, since number has xsd:unique constraint, the value should be unique in its parent scope. But in my above XML, the values for "number" and "digit" are same, which is 2. When i validate the XML with XSD, i am not seeing any error.

SO i believe my understanding is not correct. Can someone explain how xsd:unique works?

Thanks a lot,
Karuna
Apr 4 '08 #1
1 2645
jkmyoung
2,057 Recognized Expert Top Contributor
First off:
Your constraint is in the wrong place.
This makes sure that the number element's number children are unique. eg,
Expand|Select|Wrap|Line Numbers
  1. <root>
  2.  <number>
  3.    <number>2</number>
  4.    <number>2</number>
  5.  </number>
  6. </root>
  7.  
Move the constraint to the root node.

Secondly, your selector xpath on lists numbers
you want "number|dig it", or perhaps "*"

http://www.w3schools.com/schema/el_unique.asp
Apr 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3749
by: Edouard Mercier | last post by:
Hi to all; I have a very basic question: is is possible in XML Schema to express that two attributes on an XML element are exclusive, and if yes, what is the most appropriate idiomatic syntax for that ? I am grateful for your help. Regards, Edouard
7
7657
by: hyppos | last post by:
Hi, I've a XML Schema with this user Type <xsd:simpleType name="ResultArrayType"> <xsd:restriction base="xsd:nonNegativeInteger"> <xsd:maxExclusive value="1000"/> </xsd:restriction> </xsd:simpleType> How can I add an unique costraint to this type?
2
3601
by: Sebastian Kerekes | last post by:
Greetings, I'm new to XSD and I'm trying to create a schema for the following: The document 'persons' should contain 0+ elements of type 'person', which has a subelement called 'name' which is a complex type consisting of the elements 'firstname' and 'lastname'. 'name' should be unique, no combination of firstname and lastname should appear twice. And that's where I fail, at least XMLSpy tells my, that my code is not correct. I had a...
1
1516
by: Mike | last post by:
I have a dataset that I need to validate. Here an example similar to what I need to do: <Company> <Employee> <Name>...</Name> <EmployeeID>1234</EmployeeID> </Employee> <Employee> <Name>...</Name>
6
1293
by: Dizzy Haze | last post by:
This is probably a really dumb question, but I'm trying to get my head around what's going on here. I have this in my document: <div xml:id="Area_0"> <svg xmlns="http://www.w3.org/2000/svg"> <rect svg:id="Area_0" x="49" y="116" width="64" height="64"/> <rect svg:id="Area_1" x="250" y="272" width="128" height="130"/> </svg>
2
1973
by: Uma Abhyankar | last post by:
Hello, I had a program in .NET Beta1, where in I was programmatically traversing the Xml Schema using the given code snippet. However today with migration to Beta2, I am facing a compilation issue that LocalElements property on XmlSchemaComplexType not found. I now dont know how to traverse XSD programmatically!!! - I have a 4 level heirarchy XSD with a mix and match of complex elements containing content and attributes both!
2
309
by: Kent Boogaart | last post by:
Hello, I have a document structure similar to this: <root> <things> <thing id="thing1" type="type1"/> <thing id="thing2" type="type2"/> <thing id="thing3" type="type1"/> </things>
2
2007
by: Miguel Isidoro | last post by:
Hi all, I am trying to include a xsd:unique element in my schema to make an attribute of an element unique at the whole document level. Consider the following xml fragment: <Form> <Question> <Response id="response1">
0
1424
by: pr | last post by:
I have the following sample XML File: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <parent> <child ref="1"><grandchild>tom</grandchild></child> <child ref="1"><grandchild>harry</grandchild></child> </parent> And the schema is:
0
8428
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
8341
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
8851
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
8754
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
8542
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
8630
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...
1
6181
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
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.