You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by ka...@wipro.com on 2008/04/04 16:13:36 UTC

Will Sax support xsd:unique?

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


RE: Will Sax support xsd:unique?

Posted by ka...@wipro.com.
Hi Alberto,

I changed the Schema's as suggested by you and could validate the schema
for xsd:unique, xsd:key and xsd:keyref constructs.
When i am validating my XML using Xerces-C v 2.8, i get following error
messages. I am not seeing the name of the constraint in SAX error
messages. Is there any way to get the name of the failed constraint in
SAX error message?
 
Unique Key:
 
Constraint definition:
 
                <xsd:unique name="clAgentClientEntryUnique">
                        <xsd:selector
xpath="c:clAgentClientTable/c:clAgentClientEntry"/>
                        <xsd:field xpath="c:clAgentClientProcessId"/>
                </xsd:unique>

SAX error message:
        

Error at file
/home/wimax/karuna/PBCM/xerces2.8/xerces-c-src_2_8_0/bin/NECB.xml, line
208, char 65

  Message: Duplicate unique value declared for identity constraint of
element 'CLM'
 
Primary Key:
 
Constraint definition:
 
            <xsd:key name="clAgentClientEntryKey">
                        <xsd:selector
xpath="c:clAgentClientTable/c:clAgentClientEntry"/>
                        <xsd:field xpath="@clAgentClientId"/>
                </xsd:key>
 
SAX error message:
 

Error at file
/home/wimax/karuna/PBCM/xerces2.8/xerces-c-src_2_8_0/bin/NECB.xml, line
210, char 49

  Message: Duplicate key value declared for identity constraint of
element 'CLM'.

 

Reference Key:
 
Constraint definition:
 
                <xsd:key name="clAgentClientGroupDefinitionEntryKey">
                        <xsd:selector
xpath="c:clAgentClientGroupDefinitionTable/c:clAgentClientGroupDefinitio
nEntry"/>
                        <xsd:field xpath="@clAgentClientGroupId"/>
                </xsd:key>
                       <xsd:keyref name="clAgentClientEntryRefKeyTwo"
refer="clAgentClientGroupDefinitionEntryKey">
                        <xsd:selector
xpath="c:clAgentClientTable/c:clAgentClientEntry"/>
                        <xsd:field xpath="c:clAgentClientGroup"/>
                    </xsd:keyref> 
 
SAX error message:
 
   Error at file
/home/wimax/karuna/PBCM/xerces2.8/xerces-c-src_2_8_0/bin/NECB.xml, line
227, char 13 

  Message: The key for identity constraint of element 'CLM' is not
found.

Regards,
Karuna

-----Original Message-----
From: karuna.kosaraju@wipro.com [mailto:karuna.kosaraju@wipro.com]
Sent: Tuesday, April 08, 2008 7:42 PM
To: c-users@xerces.apache.org
Subject: RE: Will Sax support xsd:unique?

Thanks Alberto, Validation is going perfect now :-) 

-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com]
Sent: Tuesday, April 08, 2008 6:56 PM
To: c-users@xerces.apache.org
Subject: Re: Will Sax support xsd:unique?

karuna.kosaraju@wipro.com wrote:
>
> Thanks Alberto. However, When I am trying to enforce unique constraint

> on single attribute for multiple instances,I am still facing
> difficulty.Here is my sample XML
>
>                         <CLM:ClientTable>
>                                 <CLM:ClientEntry ClientId="1">
>                                        
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                                 <CLM:ClientEntry ClientId="2">
>                                        
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                                 <CLM:ClientEntry ClientId="3">
>                                        
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                         </CLM:ClientTable>
>
> I am trying to make *ClientProcessId* Unique across different
> "*ClientEntry*" and attached schema fails to do so. Any pointers would

> be of great help!
>

The elements are in a namespace, so you should write

            <xsd:selector xpath="c:ClientTable/c:ClientEntry"/>
            <xsd:field xpath="c:ClientProcessId"/>

and add a xmlns:c="CLM" to the root element XPath expressions ignore the
default namespace, in order to be able to always reference the empty
namespace (http://www.w3.org/TR/xpath#node-tests)

Alberto

> Thanks,
> Karuna
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Friday, April 04, 2008 7:56 PM
> To: c-users@xerces.apache.org
> Subject: Re: Will Sax support xsd:unique?
>
> 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
>
> karuna.kosaraju@wipro.com 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
> >
> >
> > 
>
> 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
>



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




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


RE: Will Sax support xsd:unique?

Posted by ka...@wipro.com.
Thanks Alberto, Validation is going perfect now :-)  

-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Tuesday, April 08, 2008 6:56 PM
To: c-users@xerces.apache.org
Subject: Re: Will Sax support xsd:unique?

karuna.kosaraju@wipro.com wrote:
>
> Thanks Alberto. However, When I am trying to enforce unique constraint

> on single attribute for multiple instances,I am still facing 
> difficulty.Here is my sample XML
>
>                         <CLM:ClientTable>
>                                 <CLM:ClientEntry ClientId="1">
>                                         
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                                 <CLM:ClientEntry ClientId="2">
>                                         
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                                 <CLM:ClientEntry ClientId="3">
>                                         
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                         </CLM:ClientTable>
>
> I am trying to make *ClientProcessId* Unique across different 
> "*ClientEntry*" and attached schema fails to do so. Any pointers would

> be of great help!
>

The elements are in a namespace, so you should write

            <xsd:selector xpath="c:ClientTable/c:ClientEntry"/>
            <xsd:field xpath="c:ClientProcessId"/>

and add a xmlns:c="CLM" to the root element XPath expressions ignore the
default namespace, in order to be able to always reference the empty
namespace (http://www.w3.org/TR/xpath#node-tests)

Alberto

> Thanks,
> Karuna
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Friday, April 04, 2008 7:56 PM
> To: c-users@xerces.apache.org
> Subject: Re: Will Sax support xsd:unique?
>
> 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
>
> karuna.kosaraju@wipro.com 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
> >
> >
> >  
>
> 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
>



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


Re: Will Sax support xsd:unique?

Posted by Alberto Massari <am...@datadirect.com>.
karuna.kosaraju@wipro.com wrote:
>
> Thanks Alberto. However, When I am trying to enforce unique constraint 
> on single attribute for multiple instances,I am still facing 
> difficulty.Here is my sample XML
>
>                         <CLM:ClientTable>
>                                 <CLM:ClientEntry ClientId="1">
>                                         
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                                 <CLM:ClientEntry ClientId="2">
>                                         
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                                 <CLM:ClientEntry ClientId="3">
>                                         
> <CLM:ClientProcessId>*12*</CLM:ClientProcessId>
>                                 </CLM:ClientEntry>
>                         </CLM:ClientTable>
>
> I am trying to make *ClientProcessId* Unique across different 
> "*ClientEntry*" and attached schema fails to do so. Any pointers would 
> be of great help!
>

The elements are in a namespace, so you should write

            <xsd:selector xpath="c:ClientTable/c:ClientEntry"/>
            <xsd:field xpath="c:ClientProcessId"/>

and add a xmlns:c="CLM" to the root element
XPath expressions ignore the default namespace, in order to be able to 
always reference the empty namespace (http://www.w3.org/TR/xpath#node-tests)

Alberto

> Thanks,
> Karuna
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Friday, April 04, 2008 7:56 PM
> To: c-users@xerces.apache.org
> Subject: Re: Will Sax support xsd:unique?
>
> 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
>
> karuna.kosaraju@wipro.com 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
> >
> >
> >  
>
> 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
>



RE: Will Sax support xsd:unique?

Posted by ka...@wipro.com.
Thanks Alberto. However, When I am trying to enforce unique constraint
on single attribute for multiple instances,I am still facing
difficulty.Here is my sample XML

                        <CLM:ClientTable>
                                <CLM:ClientEntry ClientId="1">
 
<CLM:ClientProcessId>12</CLM:ClientProcessId>
                                </CLM:ClientEntry>
                                <CLM:ClientEntry ClientId="2">
 
<CLM:ClientProcessId>12</CLM:ClientProcessId>
                                </CLM:ClientEntry>
                                <CLM:ClientEntry ClientId="3">
 
<CLM:ClientProcessId>12</CLM:ClientProcessId>
                                </CLM:ClientEntry>
                        </CLM:ClientTable>

I am trying to make ClientProcessId Unique across different
"ClientEntry" and attached schema fails to do so. Any pointers would be
of great help!

Thanks,
Karuna

-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com
<ma...@datadirect.com> ]
Sent: Friday, April 04, 2008 7:56 PM
To: c-users@xerces.apache.org
Subject: Re: Will Sax support xsd:unique?

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
<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

karuna.kosaraju@wipro.com 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
<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
<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
>
>
>  



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


Re: Will Sax support xsd:unique?

Posted by Alberto Massari <am...@datadirect.com>.
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

karuna.kosaraju@wipro.com 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
>
>
>