Jump to content
tipone

Do Not Allow To Repeat Equal Element Values

Recommended Posts

Hi, gurus! I have a list of values in element <Paz><StatussR> <Paz>A</Paz> <Paz>B</Paz> <Paz>C</Paz></StatussR>I want not to allow to repeat a values in <Paz> in <StatussR> element. for example:<StatussR> <Paz>A</Paz> <Paz>B</Paz> <Paz>B</Paz></StatussR>HOW to declare it in Schema ?Also, is there any possibility how to define the Exact order of the <PAZ> should have? Alphabeticaly or some other?

Share this post


Link to post
Share on other sites

We have a keyword called xs:key in XML Schema to define unique elements that are not null. This will ensure that values are not repeated and that they are unique. To use xs:key we need to understand xs:selector and xs:field.If you would like to define a unique element that can be null it could be done using xs:unique keyword.For knowing more please refer to my article at http://technologyandleadership.com/xml-sch...y-and-xskeyref/

Share this post


Link to post
Share on other sites

Hey its not hard. It is very easy. If you try this code it will not allow repeating values for Paz:

<?xml version="1.0" encoding="UTF-8"?><xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">	<xs:element name="StatussR">		<xs:complexType>			<xs:sequence>				<xs:element name="Paz" maxOccurs="unbounded"/>			</xs:sequence>		</xs:complexType>		<xs:key name="keyPAZ">			<xs:selector xpath="StatussR"/>			<xs:field xpath="Paz"/>		</xs:key>	</xs:element></xs:schema>

Thank you for your answer! Looks hard, but enivey it is a solution

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...