Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 10th, 2006, 06:15 AM
sachinik19@gmail.com
Guest
 
Posts: n/a
Default Unable to validate using <xs:unique> with field of integer type

Hi,

xml file :
-------------
<?xml version='1.0'?>
<query xmlns='jabber:iq:privacy'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.w3.org/2001/XMLSchema'
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>

  #2  
Old March 10th, 2006, 09:45 AM
George Bina
Guest
 
Posts: n/a
Default Re: Unable to validate using <xs:unique> with field of integer type

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.w3.org/2001/XMLSchema"
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/Debugger
http://www.oxygenxml.com

  #3  
Old March 10th, 2006, 02:35 PM
sachinik19@gmail.com
Guest
 
Posts: n/a
Default Re: Unable to validate using <xs:unique> with field of integer type

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

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles