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

xsd: unique name element

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 look at some sources in the internet, to me the code
seems correct ..

Could someone have a look at the following code and tell my what my
fault is?

Thanks for you answers in advance,

Sebastian

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="persons">
<xs:complexType>
<xs:all>
<xs:element name="person">
<xs:unique>
<xs:selector xpath="."/>
<xs:field xpath="./name/firstname"/>
</xs:unique>
<xs:complexType>
<xs:all>
<xs:element name="name" type="name"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:complexType name="name">
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:schema>
Jul 20 '05 #1
2 3575


Sebastian Kerekes wrote:
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.


Here is a working schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="person" type="personType" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:unique name="uniquePersonsByName">
<xs:selector xpath="person" />
<xs:field xpath="name/firstname" />
<xs:field xpath="name/lastname" />
</xs:unique>
</xs:element>

<xs:complexType name="personType">
<xs:sequence>
<xs:element name="name" type="nameType" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="nameType">
<xs:sequence>
<xs:element name="firstname" type="xs:string" />
<xs:element name="lastname" type="xs:string" />
</xs:sequence>
</xs:complexType>

</xs:schema>

And here an instance that causes a validation error:

<?xml version="1.0" encoding="UTF-8"?>
<persons
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2004110201Xsd.x ml">
<person>
<name>
<firstname>Martin</firstname>
<lastname>Honnen</lastname>
</name>
</person>
<person>
<name>
<firstname>Michael</firstname>
<lastname>Honnen</lastname>
</name>
</person>
<person>
<name>
<firstname>Martin</firstname>
<lastname>Honnen</lastname>
</name>
</person>
</persons>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Martin Honnen wrote:
Here is a working schema:
[..]
And here an instance that causes a validation error:
[..]


Thank you very much! :)

Sebastian
Jul 20 '05 #3

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

Similar topics

2
by: monsterpot | last post by:
Hello, I have a document like this: <parameters> <param ptype="init">somedata</param> <param ptype="process">moredata</param> <param ptype="kill">alsodata</param> </parameters> <param> has...
1
by: jack | last post by:
using the following xsd code : <xs:element name="tblUsers"> <xs:complexType> <xs:sequence> <xs:element name="UserID" type="xs:int" /> <xs:element name="FullName" type="xs:string" />...
3
by: ciaran.mchale | last post by:
Hi folks, I downloaded the binary version of Xerces C++ 2.7.0 for Windows and am using it to help me get up to speed with XML and XML Schema. So please excuse me if this is a "novice" question....
1
by: Ganesh Muthuvelu | last post by:
Hello, Let us say I have a schema file like this sample below. How would I using ..NET classes be able to read this XSD file and get all the values for each element, such as "name", "type",...
2
by: gisleyt | last post by:
Is it possibly to specify that I want a either a element or an attribute to occur, but not both at the same time? <xs:complexType name="foo"> <xs:sequence> <xs:element minOccurs="0" ref="bar"/>...
6
by: RickH | last post by:
Hello, I would like to create a user XSD data type that inherits from the w3 standard data type called ID to make sure a certain repeated element always contains distinct values. The problem is...
4
by: Eric | last post by:
Attached is an example of my question. Note the "values" attribute is optional. Also the <valuesub-element is optional. Here, the XML can contain, 1 or both or neither. I would like to allow...
3
by: David Kastrup | last post by:
Hi, not sure this is the right group (better ideas?), but anyway: is it possible in an xsd Scheme to specify that some element must have exactly one of _either_ an attribute called "name" or an...
1
by: reachkaruna | last post by:
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"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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...

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.