Unique Doesn't Work

This should cover W3C XML Schema, Relax NG and DTD related problems.
DITAToo
Posts: 2

Unique Doesn't Work

Thu Jan 16, 2014 3:42 pm

Hi All,

I have the following XML file (I deleted from this example the reference to the XML schema to keep it clean):

Code: Select all

<command_group>
    <command>
        <command_name>10</command_name>
        <command_description>My command description</command_description>
    </command>
    <command>
       <command_name>12</command_name>
       <command_description>My another command description</command_description>
    </command>
    <command>
        <command_name>10</command_name>
        <command_description>ewewe</command_description>
    </command>
</command_group>


This is my XML schema:

Code: Select all

<xs:element name="command_group">
   <xs:complexType>
      <xs:sequence>
            <xs:element name="command" minOccurs="1" maxOccurs="unbounded">
            <xs:complexType>
               <xs:sequence>
                  <xs:element name="command_name" type="xs:integer" />
                  <xs:element name="command_description" type="xs:string" />                  
               </xs:sequence>
            </xs:complexType>      
         </xs:element>
      </xs:sequence>      
   </xs:complexType>            
   <xs:unique name="uniqueCommand">
      <xs:selector xpath="command" />
      <xs:field xpath="command_name" />
   </xs:unique>
</xs:element>


I would expect that the XML file wouldn't pass the validation because "10" appears twice as the value of <command_name>. But Oxygen keeps saying that the file is OK. If I intentionally try to do other invalid things (just to check that the schema is working at all), like entering string values into <command_name>, it does say that I entered an invalid value.

Am I doing anything wrong?

Thanks!
Alex
adrian
Posts: 2443

Re: Unique Doesn't Work

Thu Jan 16, 2014 6:33 pm

Hi,

Using just the code snippets that you provided, it doesn't pass validation. Both Xerces and Saxon-EE report the problem:

Code: Select all

E [Xerces] cvc-identity-constraint.4.1: Duplicate unique value [10] declared for identity constraint "uniqueCommand" of element "command_group".

Code: Select all

E [Saxon-EE 9.5.1.2] Non-unique value found for constraint uniqueCommand: 10

Is there a target namespace for the schema?
If that's the case, note that the XPath expressions used in the @xpath attributes need the appropriate namespace to be specified. Have a look at the "personal.xsd" sample file from the Oxygen samples (Oxygen/samples/personal.xsd).

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
DITAToo
Posts: 2

Re: Unique Doesn't Work

Thu Jan 16, 2014 7:03 pm

Hi Adrian,

That's it! targetNamespace caused the problem. I got rid of it, and it's working fine now.

Thank you very much,
Alex

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests