Your schema is wrong; you are defining the unique constraint inside the <number> element, but you need to place it in the <root> element. Also, if you want to detect duplicates between <number> and <digit>, you need to add both to your xs:unique

<?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:unique name="numberUnique">
           <xs:selector xpath="number | digit"></xs:selector>
           <xs:field xpath="."></xs:field>
       </xs:unique>
   </xs:element>
   <xs:element name="number" type="xs:integer"/>
   <xs:element name="digit" type="xs:integer"/>
</xs:schema>

Alberto

[EMAIL PROTECTED] wrote:
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 using SAX, i am not seeing any error.
Can SAX support xsd:unique constraint? if yes, why the error was not
reported for above case
Thanks a lot, Karuna The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.

www.wipro.com



Reply via email to