Author Topic: XSD Schema generation with choices  (Read 6325 times)

david.bowman

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
XSD Schema generation with choices
« on: October 11, 2006, 07:35:48 am »
Hi,

I'm trying to generate a schema that will ultimately be transformed into a class that has a property that returns an array of elements.

The schema below (hand coded) correctly does this when pushed through xsd.exe (Microsoft Visual Studio 2005).

<?xml version="1.0"?>
<xs:schema targetNamespace="http://www.testStuff.com/Handler" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:hnd="http://www.testStuff.com/InHand" xmlns:ce="http://www.testStuff.com/CanonicalEvents">
<xs:import namespace="http://www.testStuff.com/CanonicalEvents"/>
<xs:element name="InHand" type="hnd:InHand"/>
<xs:complexType name="InHand">
<xs:sequence>
<xs:element name="inHandDateTime" type="xs:dateTime"/>
<xs:element name="inHandId" type="xs:unsignedLong"/>
<xs:element name="inHandEvents" minOccurs="0" maxOccurs="1" type="hnd:ArrayofEvents"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayofEvents">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="OpenEvent" type="ce:OpenEvent"/>
<xs:element name="CloseEvent" type="ce:CloseEvent"/>
<xs:element name="WarningEvent" type="ce:WarningEvent"/>
<xs:element name="VoidEvent" type="ce:VoidEvent"/>
<xs:element name="TimeoutEvent" type="ce:TimeoutEvent"/>
<xs:element name="BalanceEvent" type="ce:BalanceEvent"/>
<xs:element name="ReturnEvent" type="ce:ReturnEvent"/>
</xs:choice>
</xs:complexType>
</xs:schema>

The problem that I have is that I can't model this in EA. Even if I import this and roundtrip out, it still doesn't generate this schema. The specific problem appears to be with the unbounded choice. No matter what I use in EA I can't get it to properly generate the array in the form listed above.

I get this instead:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema targetNamespace="http://www.testStuff.com/Handler" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:hnd="http://www.testStuff.com/InHand" xmlns:ce="http://www.testStuff.com/CanonicalEvents">
<xs:import namespace="http://www.testStuff.com/CanonicalEvents"/>
<xs:element name="InHand" type="hnd:InHand"/>
<xs:complexType name="InHand">
<xs:sequence>
<xs:element name="handDateTime" type="xs:dateTime"/>
<xs:element name="handId" type="xs:unsignedLong"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="OpenEvent" type="ce:OpenEvent"/>
<xs:element name="CloseEvent" type="ce:CloseEvent"/>
<xs:element name="WarningEvent" type="ce:WarningEvent"/>
<xs:element name="VoidEvent" type="ce:VoidEvent"/>
<xs:element name="ValueEvent" type="ce:ValueEvent"/>
<xs:element name="TimeoutEvent" type="ce:TimeoutEvent"/>
<xs:element name="BalanceEvent" type="ce:BalanceEvent"/>
<xs:element name="ReturnEvent" type="ce:ReturnEvent"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:schema>

Which is close, but no cigar. I've tried introducing an intermediary element, a complex type and just about everthing in between but to no avail.

Anyone seen / fixed / worked around this?

Thanks,

D.

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: XSD Schema generation with choices
« Reply #1 on: October 16, 2006, 03:19:42 pm »
Hi there.

It seems to work for me in EA (apart from the extra root element EA puts in when you generate the XSD back out - which you just delete).  

Which version of EA are you using? (I am using the latest - 6.5.798)

I don't know why your EA collapses into only one complex type.

1. I imported your XSD (your original version at the top).  I got the 2 distinct complex types generated in EA
2. I then generated the following XSD out of EA.

<?xml version="1.0"?>
<xs:schema targetNamespace="http://www.testStuff.com/Handler" xmlns:ce="http://www.testStuff.com/CanonicalEvents" xmlns:hnd="http://www.testStuff.com/InHand" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.testStuff.com/CanonicalEvents"/>
<xs:element name="ArrayofEvents" type="ArrayofEvents"/>
<xs:complexType name="ArrayofEvents">
<xs:choice>
<xs:element name="BalanceEvent" type="ce:BalanceEvent"/>
<xs:element name="CloseEvent" type="ce:CloseEvent"/>
<xs:element name="OpenEvent" type="ce:OpenEvent"/>
<xs:element name="ReturnEvent" type="ce:ReturnEvent"/>
<xs:element name="TimeoutEvent" type="ce:TimeoutEvent"/>
<xs:element name="VoidEvent" type="ce:VoidEvent"/>
<xs:element name="WarningEvent" type="ce:WarningEvent"/>
</xs:choice>
</xs:complexType>
<xs:element name="InHand"/>
<xs:element name="InHand" type="InHand"/>
<xs:complexType name="InHand">
<xs:sequence>
<xs:element name="inHandDateTime" type="xs:dateTime"/>
<xs:element name="inHandEvents" type="hnd:ArrayofEvents" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="inHandId" type="xs:unsignedLong"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Have I missed something?

Cheers,
David.
« Last Edit: October 16, 2006, 03:20:06 pm by Dave_Bullet »
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

david.bowman

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: XSD Schema generation with choices
« Reply #2 on: October 17, 2006, 05:24:47 pm »
Hi,

Thanks for the reply and the effort.

Actually there is a subtle difference with the code generated and the code imported. If you look at where EA has put the minOccurs and maxOccurs attributes you will see that it has shifted them from being attributes on the choice to being attributes on the element that refers to the complex type containing the choice.

This subtle difference makes all the difference in the code that is ultimately generated from the schema. In your case, XSD.exe will generate a single class that can act as an element of an array, and another property that occurs only once. It does not generate an array at all.

Regards,

D

david.bowman

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: XSD Schema generation with choices
« Reply #3 on: April 03, 2007, 05:06:00 am »
So I'm back on this one again.

Just wondering if anyone has made any progress on adding the minOccurs and maxOccurs attributes to the choice. I've been modifying it by hand all this time.

I still see that the current version of ea won't allow me to specify these attributes on a complex type with a model group of choice.

Anyone?

D

ukmtk

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
Re: XSD Schema generation with choices
« Reply #4 on: April 03, 2007, 08:50:23 am »
Have you raised a fault report about this?

I know from experience that schema processing is non-trivial.