Unable to validate using <xs:unique> with field of integer type

Unable to validate using <xs:unique> with field of integer type

Post by sachinik1 » Sat, 11 Mar 2006 15:00:55


Hi,

xml file :
-------------
<?xml version='1.0'?>
<query xmlns='jabber:iq:privacy'
xmlns:xsi=" http://www.yqcomputer.com/ "
xsi:schemaLocation="jabber:iq:privacy privacy.xsd">
<list name="hello">
<item action='allow' order="1"/>
<item action='allow' order="1"/>
</list>
</query>


I want to validate such that the value of the 'order' attribute of
<item> in a <list> should be unique. for that purpose i written the xsd
below, but it is validating successfully the above xml where the value
of order is repeating (both having value '1').
thanks in advance for ur valuable suggestions-

xsd file :
------------
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema
xmlns:xs=' http://www.yqcomputer.com/ '
targetNamespace='jabber:iq:privacy'
xmlns='jabber:iq:privacy'
elementFormDefault='qualified'>

<xs:element name='query'>
<xs:complexType>
<xs:sequence>
<xs:element ref='list'
minOccurs='0'
maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name='list'>
<xs:complexType>
<xs:sequence>
<xs:element ref='item'
minOccurs='0'
maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
<xs:unique name="item1">
<xs:selector xpath="item"/>
<xs:field xpath="@order"/>
</xs:unique>
</xs:element>

<xs:element name='item'>
<xs:complexType>
<xs:attribute name='order'
type='xs:unsignedInt'
use='required'/>
</xs:attribute>
</xs:element>
</xs:schema>
 
 
 

Unable to validate using <xs:unique> with field of integer type

Post by George Bin » Sat, 11 Mar 2006 18:32:37

Hi,

In the unique constraint you defined a selector to match item elements
in no namespace (in XPath 1.0 there is no notion of default namespace
and your XPath nametest item means the item element from no namespace).
You need to declare the element namespace associated with a prefix and
use that prefix to qualify the nametest in the XPath expression. I also
added a couple of missing attribute declarations to your schema and a
working sample is below:

<?xml version='1.0' encoding='UTF-8'?>
<xs:schema xmlns:xs=" http://www.yqcomputer.com/ "
targetNamespace="jabber:iq:privacy"
xmlns="jabber:iq:privacy" elementFormDefault="qualified"
xmlns:privacy="jabber:iq:privacy">

<xs:element name="query">
<xs:complexType>
<xs:sequence>
<xs:element ref="list" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name"/>
</xs:complexType>
<xs:unique name="item1">
<xs:selector xpath="privacy:item"/>
<xs:field xpath="@order"/>
</xs:unique>
</xs:element>

<xs:element name="item">
<xs:complexType>
<xs:attribute name="order" type="xs:unsignedInt" use="required"/>
<xs:attribute name="action"/>
</xs:complexType>
</xs:element>
</xs:schema>

Best Regards
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/De ***
http://www.yqcomputer.com/

 
 
 

Unable to validate using <xs:unique> with field of integer type

Post by sachinik1 » Sat, 11 Mar 2006 23:18:42

Thanks a lot for the solution. its working fine now.