[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: schema validate key uniqueness attribute (name) of element


jaxb xs key
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@w...
Author, Definitive XML Schema     (Prentice Hall PTR)
-----------------------------------------------------  

> -----Original Message-----
> From: Pedro Salazar [mailto:pedro-b-salazar@p...] 
> Sent: Friday, February 20, 2004 11:52 AM
> To: XML DEV
> Subject:  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>
> 
> 


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.