0
我有以下XSD片:gSOAP的XS:選擇渲染重複父元素
<xs:element name="MESSAGE">
<xs:complexType>
<xs:sequence>
<xs:element ref="HEADER"/>
<xs:element ref="BODY" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="VERSION" type="xs:unsignedInt" use="required"/>
</xs:complexType>
</xs:element>
...
<xs:element name="BODY">
<xs:complexType>
<xs:choice maxOccurs="2">
<xs:element ref="LANE" minOccurs="0" maxOccurs="1"/>
<xs:element ref="DEVICE" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="TRIP" minOccurs="0" maxOccurs="1"/>
<xs:element ref="CASH_DISPOSAL" minOccurs="0" maxOccurs="1"/>
<xs:element ref="ISSUE" minOccurs="0" maxOccurs="1"/>
<xs:element ref="SHIFT" minOccurs="0" maxOccurs="1"/>
<xs:element ref="SALE_RECHARGE" minOccurs="0" maxOccurs="1"/>
<xs:element ref="LIFE" minOccurs="0" maxOc`enter code here`curs="1"/>
<xs:element ref="OBSERVATION" minOccurs="0" maxOccurs="1"/>
<xs:element ref="SURVEY_RESPONSE" minOccurs="0" maxOccurs="1"/>
<xs:element ref="BLOCK_USER" minOccurs="0" maxOccurs="1"/>
<xs:element ref="ACTION" minOccurs="0" maxOccurs="1"/>
<xs:element ref="SPECIALACTION" minOccurs="0" maxOccurs="1"/>
<xs:element ref="TEXT" minOccurs="0" maxOccurs="1"/>
<xs:element ref="RESEND" minOccurs="0" maxOccurs="1"/>
<xs:element ref="TRIP_RESEND" minOccurs="0" maxOccurs="1"/>
<xs:element ref="DISPLAY" minOccurs="0" maxOccurs="1"/>
<xs:element ref="DEBT_CANCELLATION" minOccurs="0"/>
</xs:choice>
</xs:complexType>
</xs:element>
...
這是由gSOAP的產生soapStub:
#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) /**< union variant selector value for member LANE_ */
LANE *LANE_;
#define SOAP_UNION_union_BODY_DEVICE_ (2) /**< union variant selector value for member DEVICE_ */
std::vector<std::shared_ptr<DEVICE> > *DEVICE_;
#define SOAP_UNION_union_BODY_TRIP_ (3) /**< union variant selector value for member TRIP_ */
TRIP *TRIP_;
#define SOAP_UNION_union_BODY_CASH_USCOREDISPOSAL_ (4) /**< union variant selector value for member CASH_USCOREDISPOSAL_ */
CASH_USCOREDISPOSAL *CASH_USCOREDISPOSAL_;
#define SOAP_UNION_union_BODY_ISSUE_ (5) /**< union variant selector value for member ISSUE_ */
ISSUE *ISSUE_;
#define SOAP_UNION_union_BODY_SHIFT_ (6) /**< union variant selector value for member SHIFT_ */
SHIFT *SHIFT_;
#define SOAP_UNION_union_BODY_SALE_USCORERECHARGE_ (7) /**< union variant selector value for member SALE_USCORERECHARGE_ */
SALE_USCORERECHARGE *SALE_USCORERECHARGE_;
#define SOAP_UNION_union_BODY_LIFE_ (8) /**< union variant selector value for member LIFE_ */
LIFE *LIFE_;
#define SOAP_UNION_union_BODY_OBSERVATION_ (9) /**< union variant selector value for member OBSERVATION_ */
OBSERVATION *OBSERVATION_;
#define SOAP_UNION_union_BODY_SURVEY_USCORERESPONSE_ (10) /**< union variant selector value for member SURVEY_USCORERESPONSE_ */
SURVEY_USCORERESPONSE *SURVEY_USCORERESPONSE_;
#define SOAP_UNION_union_BODY_BLOCK_USCOREUSER_ (11) /**< union variant selector value for member BLOCK_USCOREUSER_ */
BLOCK_USCOREUSER *BLOCK_USCOREUSER_;
#define SOAP_UNION_union_BODY_ACTION_ (12) /**< union variant selector value for member ACTION_ */
ACTION *ACTION_;
#define SOAP_UNION_union_BODY_SPECIALACTION_ (13) /**< union variant selector value for member SPECIALACTION_ */
SPECIALACTION *SPECIALACTION_;
#define SOAP_UNION_union_BODY_TEXT_ (14) /**< union variant selector value for member TEXT_ */
TEXT *TEXT_;
#define SOAP_UNION_union_BODY_RESEND_ (15) /**< union variant selector value for member RESEND_ */
RESEND *RESEND_;
#define SOAP_UNION_union_BODY_TRIP_USCORERESEND_ (16) /**< union variant selector value for member TRIP_USCORERESEND_ */
TRIP_USCORERESEND *TRIP_USCORERESEND_;
#define SOAP_UNION_union_BODY_DISPLAY_ (17) /**< union variant selector value for member DISPLAY_ */
DISPLAY *DISPLAY_;
#define SOAP_UNION_union_BODY_DEBT_USCORECANCELLATION_ (18) /**< 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
我建立的消息a S請按照:
MESSAGE soapMSG;
HEADER soapHeader;
BODY soapBody;
LANE soapLane;
...
soapMSG.BODY_ = std::make_shared<BODY>(); // here i use a maping pointer to sharedptr
soapMSG.BODY_->_BODY = new ((_union_BODY *)soap_malloc(ctx, 2 * sizeof(_unionBody))) _union_BODY[2];
soapMSG.BODY_->__size_BODY = 2;
soapMSG.BODY_->_BODY[0].__union_BODY = SOAP_UNION_union_BODY_LANE_;
soapMSG.BODY_->_BODY[0]._BODY.LANE_ = &soapLane;
...
的問題是: 當XSD包含的xs:選擇,gSOAP的產生並集以通過動態陣列一起使用,問題是,每_union_Body gSOAP的與父元件包括
使其<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">
<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="">
</HEADER>
<BODY>
<BODY>
<LANE STATUS="0" COLLECTOR="" SHIFT_NUMBER="0" BEGIN_DATETIME="2017-10-19 10:04:58" FUNCTION="1" WORK_MODE="2"></LANE>
</BODY>
...
</BODY>
</MESSAGE>
我該如何避免這種情況?
預先感謝您!