473,385 Members | 2,004 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,385 software developers and data experts.

xsd:unique issue

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" elementFormDefault="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:integer">
<xs:unique name="numberUnique">
<xs:selector xpath="number"></xs:selector>
<xs:field xpath="."></xs:field>
</xs:unique>
</xs:element>
<xs:element name="digit" type="xs:integer"/>
</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:noNamespaceSchemaLocation="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 2627
jkmyoung
2,057 Expert 2GB
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|digit", 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
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...
7
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>...
2
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...
1
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>...
6
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">...
2
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...
2
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
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>...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...

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.