[xsd-users] "must-be-one-of' choices in xsd

Rob Ursem Rob.Ursem at cmgl.ca
Mon Apr 28 23:33:15 EDT 2014


   I am running into an issue with the generated code r   where one of the choice options must be specified.

   Consider the following schema:


   <?xml versi
   <xsd:schema   xmlns:xs="   elementFormDefault="qu   attributeFormDefault="unqualified">

   <xsd:complexType name
   <xsd:sequence>

   <xs:choice minOccurs
   <xs:element name=&qu
   <xs:element name=&qu
   </xs:choice>
   </xsd:sequence>

   </xsd:complexType><
   </xsd:schem
   Either OptionA or OptionB
   must be given to have a valid instance of class objectA.&nbs

   The generated code shows:

   class objectA:
   {

     public:
     // Opti
     // 
     typedef
     typedef   OptionA_optional;<
     typedef   OptionA_traits;

     OptionA_optional&

     OptionA
   ...

     // Opti
     // 
     typedef
     typedef   OptionB_optional;<
     typedef   OptionB_traits;

     OptionB_optional&

     OptionB
   ...

     // Cons
     //

     objectA
   ...

     virtual

     ~object
     // Impl
     //

     protect
     void

     parse (
       
     protect
     OptionA
     OptionB
   };

    Both sides of the choice are optional and the    show that either is required. In fact, if you don't sp   elements, the object writes without any notification, resultin   invalid XML being generated.

   I could derive a subclass for every class that uses    checking can be done before the data is written but I'm hop   is a better solution to this issue?


More information about the xsd-users mailing list