Jump to content

Do Not Allow To Repeat Equal Element Values


tipone
 Share

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?

Link to comment
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/

Link to comment
Share on other sites

  • 2 weeks later...

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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...