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] References in XSD/XML

[ Lists Home | Date Index | Thread Index ]


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@nexfi.fr>           To:       xml-dev@lists.xml.org                                                   
                                               cc:                                                                               
                      08/12/2003 12:13         Subject:  [xml-dev] 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.




 

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

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