- From: Dutta, Abhijit <abhijit.dutta@logicacmg.com>
- Date: Thu, 17 Jan 2008 15:45:44 +0530
- To: "Michael Kay" <mike@saxonica.com>, <xmlschema-dev@w3.org>
- Message-ID: <90293B373640D5409D53D4119A6096D1651076@in-ex005.groupinfra.com>
Hi Michael, First, I want name and index *both* should be unique. I went through the definition of xs:unique, which usually put constraint on the values. But I want the uniqueness in the element attribute-value pair. For example, xsd file: <xsd:schema <http://www.stylusstudio.com/xml_schema_editor.html> xmlns:ipm=http://unique/test xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://unique/test" elementFormDefault="qualified"> <xsd:element name="root"> <xsd:complexType> <xsd:sequence> <xsd:element ref="ipm:mayHaveDaughter" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:unique name="uniqueNode"> <xsd:selector xpath <http://www.stylusstudio.com/xpath.html> ="ipm:mayHaveDaughter"/> <xsd:field xpath="@f1"/> <xsd:field xpath="ipm:s"/> </xsd:unique> </xsd:element> <xsd:element name="mayHaveDaughter"> <xsd:complexType> <xsd:choice> <xsd:element name="s" minOccurs="0" maxOccurs="1" type="xsd:string"/> </xsd:choice> <xsd:attribute name="f1" type="xsd:string"/> </xsd:complexType> </xsd:element> example xml file <http://blogs.stylusstudio.com/> : <?xml version="1.0"?> <root xmlns="http://unique/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://unique/test unique.xsd"> <mayHaveDaughter f1="c"> <s>100</s> </mayHaveDaughter> <mayHaveDaughter f1="c"> <s>200</s> </mayHaveDaughter> </root> Now in the above example values are different 100, 200 etc., since there is a unique constraint. My question is can I put restriction such that the element "mayHaveDaughter" *must* have different element attrib/ value pairs like, f1="c", f1="d" etc. Hope that clarifies my doubt. ~Thanx Abhijit ________________________________ From: Michael Kay [mailto:mike@saxonica.com] Sent: Thursday, January 17, 2008 2:39 PM To: Dutta, Abhijit; xmlschema-dev@w3.org Subject: RE: Uniqueness Is there a way in XSD to specify that the name and index will be unique for a set of fields? If so, could you please give an example.. You can use xs:unique. But exactly how you use it depends on having a clearer specification. Are you saying "name must be unique and index must also be unique", or are you saying "the combination of name and index must be unique" (the second option would allow two things to have the same name provided they have a different index). Also, uniqueness applies within some scope - typically there is some element E within which each child/descendant element F has a unique value for V. You need to tell us something about E, because that is where you define the constraint. Michael Kay http://www.saxonica.com/ This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
Received on Thursday, 17 January 2008 10:17:02 UTC