Book a Demo

Author Topic: XML Schema minOccurs attribute element  (Read 4260 times)

saschwarz

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
XML Schema minOccurs attribute element
« on: June 03, 2003, 06:47:30 am »
Hi
I have a class A with an association to another class B (b is an attribute of A of type B) Is there a way that I can generate:

<xs:complexType name="A">
<xs:all>
 <xs:element name="b" minOccurs="0" maxOccurs="unbounded"/>
   <xs:complexType>
     <xs:sequence>
         <xs:element ref="B" minOccurs="0" maxOccurs="unbounded"/>
     </xs:sequence>
   </xs:complexType>
 </xs:element>
</xs:all>


I've set the multiplicity of the roles on the association (that changes the min/maxOccurs within sequence). But I really want to make the presence of the entire attribute (sequence role) to be optional.

Thanks
Steve

benc

  • EA Administrator
  • EA User
  • *****
  • Posts: 200
  • Karma: +0/-0
    • View Profile
Re: XML Schema minOccurs attribute element
« Reply #1 on: June 05, 2003, 04:04:50 pm »
Hi Steve,

I can think of a couple of ways to get the effect you are after, though niether is entirely satisfactory.

1. Wrap the b attribute in a choice model group.

2. Specify the b attribute as an XSDelement stereotype with anonymousType set to true to get this:
<xs:complexType name="A">
<xs:all>
<xs:element name="A.B" type="B" minOccurs="0" maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>

As I say, this is not precisely equivalent to the schema snippet you gave, but may do the trick for now.  At some stage I'll get the generator to enable multiplicity constraints on the "source-end element".  I think if it just used the lower bound from target end multiplicity to get this:
<xs:complexType name="A">
<xs:all>
<xs:element name="b" minOccurs="0"/>
   <xs:complexType>
<xs:sequence>
    <xs:element ref="B" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
   </xs:complexType>
 </xs:element>
</xs:all>

That would do.  So b can occur 0 or 1 times and contain 0-many "B" elements.  Unfortunately, I don't believe there's a way to get the generator to do this at the moment.

Regards,
Ben.