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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] schema validate key uniqueness attribute (name) of element

[ Lists Home | Date Index | Thread Index ]

Hi,

I think you want serviceImport|serviceExport instead of
serviceImport/serviceExport in your path.  

The "|" operator means "serviceImport or serviceExport", while the slash
means that it is looking for a serviceExport child of serviceImport.

Priscilla

-----------------------------------------------------
Priscilla Walmsley             priscilla@walmsley.com
Author, Definitive XML Schema     (Prentice Hall PTR)
-----------------------------------------------------  

> -----Original Message-----
> From: Pedro Salazar [mailto:pedro-b-salazar@ptinovacao.pt] 
> Sent: Friday, February 20, 2004 11:52 AM
> To: XML DEV
> Subject: [xml-dev] schema validate key uniqueness attribute 
> (name) of elements
> 
> 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
> 
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
> 
> 





 

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

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