Book a Demo

Author Topic: Help with XSD sequence  (Read 3923 times)

pmcevoy

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Help with XSD sequence
« on: January 30, 2006, 10:40:38 am »
Hi All,
I'm having a lot of trouble generating XSD schema from my data model, and hope you can help out.

I have the following simple classes:  Order and Item.  I then setup a Composite association joing Item to Order, so that I have the following diagram:


+----------+
|Order     |
+----------+
| +orderId |
+----------+
/\
#  1  +Items
\/
|
|
| 0..*
+----------+
|Item        |
+----------+
| +itemId  |
+----------+


I then use the XSD transformation to generate an XSD model for me (I have already imported the XSD Profile).  The XSD model is very similar to above, but has the XSD stereotypes applied to it.

I then export the model as XML schema.  However, the schema is not what I expected at all.  I get:

Code: [Select]

<xs:complexType name="Order">
 <xs:sequence>
   <xs:element name="OrderId" type="xs:int"/>
   <xs:element name="Item" type="Item" minOccurs="0" maxOccurs="unbounded"/>
 </xs:sequence>
</xs:complexType>


when I expect to see:

Code: [Select]

<xs:complexType name="Order">
 <xs:sequence>
   <xs:element name="OrderId" type="xs:int"/>
   <xs:element name="Items">
     <xs:complexType>
       <xs:sequence minOccurs="0" maxOccurs="unbounded">
         <xs:element name="Item" type="Item"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
 </xs:sequence>
</xs:complexType>




I'm certain this is to do with the way I am modelling the association.  (I'm not even certain if this is syntactically correct UML).

I notice in the XSD model that none of the items is marked with an XSDsequence stereotype, so I am really confused as to how this should work (the example docs seem to be out of sync with the profile, so they are not much help).

It's not beyond me to customize the XSD transform if needed - but I have to understand how schema generation should work in the first place!

Any pointers would be appreciated.

Pete

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Help with XSD sequence
« Reply #1 on: January 30, 2006, 01:09:22 pm »
I just did a little experiment.

I made a similar model to yours, except that I moved the Items role to the other end of the aggregation.

The result seems more correct, although it uses a reference to Item instead of including the declaration of Item nested inside the declaration of Order.

pmcevoy

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Help with XSD sequence
« Reply #2 on: January 31, 2006, 02:23:52 am »
Hi Simon,
Thanks for your reply.  I tried this, and yes, it does now include the Items role in the schema.  However the XML that would be validated by this schema looks like:

<Order>
 <OrderId>0</OrderId>
 <Items>
   <ItemId>0</ItemId>
 </Items>
 <Items>
   <ItemId>1</ItemId>
 </Items>
</Order>

When I really was looking for:

<Order>
<OrderId>0</OrderId>
<Items>
  <Item>
   <ItemId>0</ItemId>
  </Item>
  <Item>
   <ItemId>0</ItemId>
  </Item>
 </Items>
</Order>

I'm certain I have modelled it wrong in the first place (or at least, my PIM may be OK, but the PSM after transformation is wrong).  

How is the XSDsequence stereotype used from the XSD Profile?

Pete

pmcevoy

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Help with XSD sequence
« Reply #3 on: January 31, 2006, 02:50:29 am »
It seems that the PSM XSD model needs to look something like:

+------------------+
| <<XSDComplexType>>
|  Order             |
+------------------+
|  +orderId          |
|  +Items : Items |
+------------------+

+------------+
|<<XSDAll>> |
|  Items         |
+------------+
+------------+
 /\
 #  1
 \/
  |
  |  0..*
+------------------+
| <<XSDComplexType |
|  Item              |
+------------------+
|  +itemId   |
+------------------+

It seems I need to create a container class.  Is this correct?

BTW, applying the XSDsequence stereotype to the container class causes an invalid XSD to be created - basically the container class does not get generated at all.

I wish there were better examples in the XSD profile documentation...

Pete