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

Re: XML Schema question on key, keyref constraints


xml keyref example
No, on several levels.

First, a nit. The example schema is not well-formed and keyref is 
spelled with lower-case 'r'.

Second, a keyref can only refer to a key defined in the same scope.

Third, even if you move the key and keyref into the same scope, the keys 
in your example are not unique. Two of them have the value "1".

It seems likely that you didn't think this should be valid when you 
posed it, as you know perfectly well that the state code must be 
combined with plateNumber to make a unique key. Must be a "teaching 
example". ;-}

Bob Foster


Murali Mani wrote:

> I have a question on XML-Schema:
> 
> Is it possible to have:
> 
> <xs:element name="vehicle">
>   <xs:complexType>
>     <xs:attribute name="plateNumber" type="xs:integer"/>
>   </xs:complexType>
> </xs:element>
> 
> <xs:element name="state">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="code" type="xs:string"/>
>       <xs:element ref="vehicle" maxOccurs="unbounded"/>
>     </xs:sequence>
>   </xs:complexType>
> 
>   <xs:key name="reg">
>     <xs:selector xpath=".//vehicle"/>
>     <xs:field xpath="@plateNumber"/>
>   </xs:key>
> </xs:element>
> 
> <xs:element name="person">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="car" maxOccurs="unbounded"/>
>         <xs:complexType>
>           <xs:attribute name="regPlate" type="xs:integer"/>
>         </xs:complexType>
>       </xs:element>
>     </xs:sequence>
>   </xs:complexType>
> 
>   <xs:keyRef name="carRef" refer="reg">
>     <xs:selector xpath=".//car"/>
>     <xs:field xpath=@regPlate"/>
>   </xs:keyRef>
> </xs:element>
> 
> Is the above a correct schema. And in that case can I have a document like
> 
> <root>
>   <state>
>     <code>CA</code>
>     <vehicle plateNumber="1"/>
>     <vehicle plateNumber="2"/>
>   </state>
>   <state>
>     <code>MA</code>
>     <vehicle plateNumber="1"/>
>   </state>
> 
>   <person>
>     <car regPlate="1"/>
>   </person>
>   <person>
>     <car regPlate="2"/>
>   </person>
> </root>
> 
> is this a valid instance for that schema??
> 
> thanks, murali.



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.