title: gsoap xs:choice render duplicate parent element
body: <p>I have the following xsd piece:</p>
  
  <pre><code>    &lt;xs:element name="MESSAGE"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element ref="HEADER"/&gt;
          &lt;xs:element ref="BODY" minOccurs="1" maxOccurs="1"/&gt;
        &lt;/xs:sequence&gt;
        &lt;xs:attribute name="VERSION" type="xs:unsignedInt" use="required"/&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;xs:element name="BODY"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:choice maxOccurs="2"&gt;
          &lt;xs:element ref="LANE" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="DEVICE" minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xs:element ref="TRIP" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="CASH_DISPOSAL" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="ISSUE" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="SHIFT" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="SALE_RECHARGE" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="LIFE" minOccurs="0" maxOc`enter code here`curs="1"/&gt;
          &lt;xs:element ref="OBSERVATION" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="SURVEY_RESPONSE" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="BLOCK_USER" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="ACTION" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="SPECIALACTION" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="TEXT" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="RESEND" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="TRIP_RESEND" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="DISPLAY" minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element ref="DEBT_CANCELLATION" minOccurs="0"/&gt;
        &lt;/xs:choice&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  </code></pre>
  
  <p>...</p>
  
  <p>this is the soapStub generated by gsoap:</p>
  
  <pre><code>#ifndef SOAP_TYPE_union_BODY
  #define SOAP_TYPE_union_BODY (88)
  /* union serializable only when used as a member of a struct or class with a union variant selector */
  union union_BODY
  {
          #define SOAP_UNION_union_BODY_LANE_ (1) /**&lt; union variant selector value for member LANE_ */
          LANE *LANE_;
          #define SOAP_UNION_union_BODY_DEVICE_   (2) /**&lt; union variant selector value for member DEVICE_ */
          std::vector&lt;std::shared_ptr&lt;DEVICE&gt; &gt; *DEVICE_;
          #define SOAP_UNION_union_BODY_TRIP_ (3) /**&lt; union variant selector value for member TRIP_ */
          TRIP *TRIP_;
          #define SOAP_UNION_union_BODY_CASH_USCOREDISPOSAL_  (4) /**&lt; union variant selector value for member CASH_USCOREDISPOSAL_ */
          CASH_USCOREDISPOSAL *CASH_USCOREDISPOSAL_;
          #define SOAP_UNION_union_BODY_ISSUE_    (5) /**&lt; union variant selector value for member ISSUE_ */
          ISSUE *ISSUE_;
          #define SOAP_UNION_union_BODY_SHIFT_    (6) /**&lt; union variant selector value for member SHIFT_ */
          SHIFT *SHIFT_;
          #define SOAP_UNION_union_BODY_SALE_USCORERECHARGE_  (7) /**&lt; union variant selector value for member SALE_USCORERECHARGE_ */
          SALE_USCORERECHARGE *SALE_USCORERECHARGE_;
          #define SOAP_UNION_union_BODY_LIFE_ (8) /**&lt; union variant selector value for member LIFE_ */
          LIFE *LIFE_;
          #define SOAP_UNION_union_BODY_OBSERVATION_  (9) /**&lt; union variant selector value for member OBSERVATION_ */
          OBSERVATION *OBSERVATION_;
          #define SOAP_UNION_union_BODY_SURVEY_USCORERESPONSE_    (10)    /**&lt; union variant selector value for member SURVEY_USCORERESPONSE_ */
          SURVEY_USCORERESPONSE *SURVEY_USCORERESPONSE_;
          #define SOAP_UNION_union_BODY_BLOCK_USCOREUSER_ (11)    /**&lt; union variant selector value for member BLOCK_USCOREUSER_ */
          BLOCK_USCOREUSER *BLOCK_USCOREUSER_;
          #define SOAP_UNION_union_BODY_ACTION_   (12)    /**&lt; union variant selector value for member ACTION_ */
          ACTION *ACTION_;
          #define SOAP_UNION_union_BODY_SPECIALACTION_    (13)    /**&lt; union variant selector value for member SPECIALACTION_ */
          SPECIALACTION *SPECIALACTION_;
          #define SOAP_UNION_union_BODY_TEXT_ (14)    /**&lt; union variant selector value for member TEXT_ */
          TEXT *TEXT_;
          #define SOAP_UNION_union_BODY_RESEND_   (15)    /**&lt; union variant selector value for member RESEND_ */
          RESEND *RESEND_;
          #define SOAP_UNION_union_BODY_TRIP_USCORERESEND_    (16)    /**&lt; union variant selector value for member TRIP_USCORERESEND_ */
          TRIP_USCORERESEND *TRIP_USCORERESEND_;
          #define SOAP_UNION_union_BODY_DISPLAY_  (17)    /**&lt; union variant selector value for member DISPLAY_ */
          DISPLAY *DISPLAY_;
          #define SOAP_UNION_union_BODY_DEBT_USCORECANCELLATION_  (18)    /**&lt; union variant selector value for member DEBT_USCORECANCELLATION_ */
          DEBT_USCORECANCELLATION *DEBT_USCORECANCELLATION_;
  };
  #endif
  
  /* D:\dd\projects\Deoban\source\Actros\developed\libs\upperLevelInterface\sep\messages.h:422 */
  #ifndef SOAP_TYPE__union_BODY
  #define SOAP_TYPE__union_BODY (67)
  /* Choice: */
  class SOAP_CMAC _union_BODY {
        public:
          /// Union with union union_BODY variant selector __union_BODY set to one of: SOAP_UNION_union_BODY_LANE_ SOAP_UNION_union_BODY_DEVICE_ SOAP_UNION_union_BODY_TRIP_ SOAP_UNION_union_BODY_CASH_USCOREDISPOSAL_ SOAP_UNION_union_BODY_ISSUE_ SOAP_UNION_union_BODY_SHIFT_ SOAP_UNION_union_BODY_SALE_USCORERECHARGE_ SOAP_UNION_union_BODY_LIFE_ SOAP_UNION_union_BODY_OBSERVATION_ SOAP_UNION_union_BODY_SURVEY_USCORERESPONSE_ SOAP_UNION_union_BODY_BLOCK_USCOREUSER_ SOAP_UNION_union_BODY_ACTION_ SOAP_UNION_union_BODY_SPECIALACTION_ SOAP_UNION_union_BODY_TEXT_ SOAP_UNION_union_BODY_RESEND_ SOAP_UNION_union_BODY_TRIP_USCORERESEND_ SOAP_UNION_union_BODY_DISPLAY_ SOAP_UNION_union_BODY_DEBT_USCORECANCELLATION_
          int __union_BODY;
          union union_BODY _BODY;
        public:
          /// Return unique type id SOAP_TYPE__union_BODY
          virtual int soap_type(void) const { return SOAP_TYPE__union_BODY; }
          /// (Re)set members to default values
          virtual void soap_default(struct soap*);
          /// Serialize object to prepare for SOAP 1.1/1.2 encoded output (or with SOAP_XML_GRAPH) by analyzing its (cyclic) structures
          virtual void soap_serialize(struct soap*) const;
          /// Output object in XML, compliant with SOAP 1.1 encoding style, return error code or SOAP_OK
          virtual int soap_put(struct soap*, const char *tag, const char *type) const;
          /// Output object in XML, with tag and optional id attribute and xsi:type, return error code or SOAP_OK
          virtual int soap_out(struct soap*, const char *tag, int id, const char *type) const;
          /// Get object from XML, compliant with SOAP 1.1 encoding style, return pointer to object or NULL on error
          virtual void *soap_get(struct soap*, const char *tag, const char *type);
          /// Get object from XML, with matching tag and type (NULL matches any tag and type), return pointer to object or NULL on error
          virtual void *soap_in(struct soap*, const char *tag, const char *type);
          /// Return a new object of type _union_BODY, default initialized and not managed by a soap context
          virtual _union_BODY *soap_alloc(void) const { return SOAP_NEW(_union_BODY); }
        public:
          /// Constructor with initializations
          _union_BODY()
          {
            __union_BODY = 0;
          }
          virtual ~_union_BODY() { }
          /// Friend allocator used by soap_new__union_BODY(struct soap*, int)
          friend SOAP_FMAC1 _union_BODY * SOAP_FMAC2 soap_instantiate__union_BODY(struct soap*, int, const char*, const char*, size_t*);
  };
  #endif
  
  /* D:\dd\projects\Deoban\source\Actros\developed\libs\upperLevelInterface\sep\messages.h:170 */
  #ifndef SOAP_TYPE_BODY
  #define SOAP_TYPE_BODY (21)
  /* complex XSD type 'BODY': */
  class SOAP_CMAC BODY {
        public:
          /// Sequence of 0 to 2 elements 'BODY' of XSD type 'union-BODY' stored in dynamic array _BODY of length __size_BODY
          int __size_BODY;
          _union_BODY *_BODY;
          /// Context that manages this object
          struct soap *soap;
        public:
          /// Return unique type id SOAP_TYPE_BODY
          virtual int soap_type(void) const { return SOAP_TYPE_BODY; }
          /// (Re)set members to default values
          virtual void soap_default(struct soap*);
          /// Serialize object to prepare for SOAP 1.1/1.2 encoded output (or with SOAP_XML_GRAPH) by analyzing its (cyclic) structures
          virtual void soap_serialize(struct soap*) const;
          /// Output object in XML, compliant with SOAP 1.1 encoding style, return error code or SOAP_OK
          virtual int soap_put(struct soap*, const char *tag, const char *type) const;
          /// Output object in XML, with tag and optional id attribute and xsi:type, return error code or SOAP_OK
          virtual int soap_out(struct soap*, const char *tag, int id, const char *type) const;
          /// Get object from XML, compliant with SOAP 1.1 encoding style, return pointer to object or NULL on error
          virtual void *soap_get(struct soap*, const char *tag, const char *type);
          /// Get object from XML, with matching tag and type (NULL matches any tag and type), return pointer to object or NULL on error
          virtual void *soap_in(struct soap*, const char *tag, const char *type);
          /// Return a new object of type BODY, default initialized and not managed by a soap context
          virtual BODY *soap_alloc(void) const { return SOAP_NEW(BODY); }
        public:
          /// Constructor with initializations
          BODY()
          {
            __size_BODY = 0;
            _BODY = NULL;
            soap = (struct soap *)0;
          }
          virtual ~BODY() { }
          /// Friend allocator used by soap_new_BODY(struct soap*, int)
          friend SOAP_FMAC1 BODY * SOAP_FMAC2 soap_instantiate_BODY(struct soap*, int, const char*, const char*, size_t*);
  };
  #endif
  </code></pre>
  
  <p>and i build the message as follow:</p>
  
  <pre><code>MESSAGE soapMSG;
      HEADER soapHeader;
      BODY soapBody;
      LANE soapLane;
  
      ...
  
  soapMSG.BODY_ = std::make_shared&lt;BODY&gt;(); // here i use a maping pointer to sharedptr
  
          soapMSG.BODY_-&gt;_BODY = new ((_union_BODY *)soap_malloc(ctx, 2 * sizeof(_unionBody))) _union_BODY[2];
  
          soapMSG.BODY_-&gt;__size_BODY = 2;
  
          soapMSG.BODY_-&gt;_BODY[0].__union_BODY = SOAP_UNION_union_BODY_LANE_;
  
          soapMSG.BODY_-&gt;_BODY[0]._BODY.LANE_ = &amp;soapLane;
  
   ...
  </code></pre>
  
  <p>the question is:
  When a xsd contains a xs:choice, gsoap generate a union to be used through dynamic array, the problem is that every _union_Body gsoap render it with the parent element included</p>
  
  <pre><code>    &lt;MESSAGE xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" VERSION="0"&gt;
          &lt;HEADER SOCIETY="0" CONCESSION="0" FROM="456" TO="123" DATETIME="1970-01-01 01:00:00" SEQUENCE="0" CODE="8" LOCAL="0" MAINTENANCE="0" CHECKSUM=""&gt;
          &lt;/HEADER&gt;
          &lt;BODY&gt;
              &lt;BODY&gt;
                  &lt;LANE STATUS="0" COLLECTOR="" SHIFT_NUMBER="0" BEGIN_DATETIME="2017-10-19 10:04:58" FUNCTION="1" WORK_MODE="2"&gt;&lt;/LANE&gt;
              &lt;/BODY&gt;
  ...
          &lt;/BODY&gt;
      &lt;/MESSAGE&gt;
  </code></pre>
  
  <p>How can i avoid this?</p>
  
  <p>thank you in advance!!</p>