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

Re: References in XSD/XML


xsd xml

Alain,

To enforce constraints between orders and assets and reference an asset in
an order, you may use key and keyref elements.

Here is an example taken from the
http://datypic.com/books/DefXMLSchema/chapter17.html

 <xsd:keyref name="prodNumKeyRef" refer="prodNumKey">
      <xsd:selector xpath="items/*"/>
      <xsd:field xpath="@number"/>
    </xsd:keyref>
    <xsd:key name="prodNumKey">
      <xsd:selector xpath=".//product"/>
      <xsd:field xpath="number"/>
    </xsd:key>

Cheers,

nada


                                                                                                                                 
                      Alain Tésio                                                                                                
                      <ate@n...>           To:       xml-dev@l...                                                   
                                               cc:                                                                               
                      08/12/2003 12:13         Subject:   References in XSD/XML                                         
                      AM                                                                                                         
                                                                                                                                 
                                                                                                                                 




Hi, I'm having problems writing a schema with elements referencing each
other. I've written a large schema with several business objects defined
in complex types.

Let's say I have two complex types "asset" and "order" in the namespace
"test", "order" has an element with the type "test:asset"

Here is the .xsd file :

================= test.xsd
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:schema targetNamespace="Test" xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:test="Test" elementFormDefault="qualified"
attributeFormDefault="unqualified">
             <xs:complexType name="order">
                         <xs:sequence>
                                     <xs:element name="Reference"
type="xs:string"/>
                                     <xs:element name="Status"
type="xs:string"/>
                                     <xs:element name="Asset"
type="test:asset"/>
                         </xs:sequence>
                         <xs:attribute name="ID" type="xs:long"
use="required"/>
             </xs:complexType>
             <xs:complexType name="asset">
                         <xs:sequence>
                                     <xs:element name="ISINCode"
type="xs:string"/>
                                     <xs:element name="Designation"
type="xs:string"/>
                         </xs:sequence>
                         <xs:attribute name="ID" type="xs:long"
use="required"/>
             </xs:complexType>
             <xs:element name="testObjects">
                         <xs:complexType name="testEntity">
                                     <xs:choice>
                                                 <xs:element name="order"
type="test:order"/>
                                                 <xs:element name="asset"
type="test:asset"/>
                                     </xs:choice>
                         </xs:complexType>
             </xs:element>
</xs:schema>
=================

And here is a valid xml file for this schema:

================= test.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<testObjects xmlns="Test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="Test
C:\tmp\test.xsd">
             <order ID="951">
                         <Reference>ATE-030912113020</Reference>
                         <Status>Executed</Status>
                         <Asset ID="5709">
                                     <ISINCode>FR0000060899</ISINCode>
                                     <Designation>BACOU
DALLOZ</Designation>
                         </Asset>
             </order>
</testObjects>
=================


What I'd like is to define the second object "asset" outside the
object "order", and have a single line in "order" referencing it
with its id, I can have several objects with the same type in one
xml file.

I think I can do this with elements and ref to elements but the
number and types of elements in the xml file depends on the object.

Thanks for your time

Alain



-----------------------------------------------------------------
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://lists.xml.org/ob/adm.pl>






------------------------------------------
This e-mail is confidential.  If you are not the intended recipient, any use, disclosure or copying of this document is unauthorised and prohibited.  If you have received this document in error, please delete the email and notify me by return email or by phoning the NEMMCO Helpdesk on 1300 300 295.

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.