OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   schema validate key uniqueness attribute (name) of elements

[ Lists Home | Date Index | Thread Index ]

Greetings,

I intend to create a schema where I could validate that an element would
have children elements but the name attribute should be unique, or more
than that, be a key! 

I've tried to define it with the element key ("service") but my tests
failed. I mean, my parser (Xerces2) and oxygen (ide tool) let pass that
constraint in my schema.

My question is if I have my schema well defined for that purpose. I put
the schema and test xml sample that should fail because I have two
elements with the same name ('service1').

Any ideas?

thanks,
Pedro Salazar.

Test case:

======= SCHEMA =========
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:med="http://med/"; targetNamespace="http://med/";>
    <xs:element name="serviceList" type="med:serviceListType">
        <xs:key name="service">
            <xs:selector xpath="serviceImport/serviceExport"/>
            <xs:field xpath="@name"/>
        </xs:key>
    </xs:element>
    <xs:element name="serviceImport" type="med:serviceImportType"/>
    <xs:element name="serviceExport" type="med:serviceExportType"/>
   <xs:complexType name="serviceImportType">
        <xs:attribute name="name" use="required" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="serviceExportType">
        <xs:attribute name="name" use="required" type="xs:string"/>
    </xs:complexType>
</xs:schema>

========= XML ==============
<?xml version="1.0" encoding="ISO-8859-1"?>
<serviceList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://med/ file:/home/psalazar/med.xsd"
    xmlns="http://med/"; name="test" version="1.0">
    <serviceImport name="service1"/>
    <serviceExport name="service1"/>
</serviceList>

-- 
PS
pedro-b-salazar_at_ptinovacao_dot_pt
PGP:0E129E31D803BC61





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS