• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

XML schema unique validation is not working

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have the problem on validate the unique value of the element. Is always pass through although there is a duplicate value on the reference name.

Can someone help me on this? Thanks a lot.

Here is the code:

XML
<?xml version="1.0" encoding="UTF-8"?>
<dl xmlns="http://www.abc.com/schema/dl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.abc.com/schema/dl
http://www.abc.com/schema/dl/dl.xsd">

<references>
<reference name="abc" value="123"/>
<reference name="abc" value="235" />
</references>
</dl>

dl.xsd

<?xml version="1.0"?>
<xs:schema xmlns="http://www.abc.com/schema/dl"
targetNamespace="http://www.abc.com/schema/dl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:element name="dl">
<xs:complexType>
<xs:sequence>
<xs:element name="references" type="references-Type" minOccurs="0" maxOccurs="1">
<xs:unique name="CheckUniqueReference">
<xs:selector xpath="reference"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="references-Type">
<xs:sequence>
<xs:element name="reference" type="referenceType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="referenceType">
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
 
kangsar kk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone can help me on this?....
 
kangsar kk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just added the xml namespace, everything will be solved.

<?xml version="1.0"?>
<xs:schema xmlns="http://www.abc.com/schema/dl"
targetNamespace="http://www.abc.com/schema/dl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns="http://www.abc.com/schema/dl"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:element name="dl">
<xs:complexType>
<xs:sequence>
<xs:element name="references" type="references-Type" minOccurs="0" maxOccurs="1">
<xs:unique name="CheckUniqueReference">
<xs:selector xpath="ns:reference"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
 
Nothing up my sleeve ... and ... presto! A tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic