如何创建一个soap_dom_element,用C中的gSOAP将其分配给__any?

问题描述 投票:0回答:1

我试图用gSOAP库将这些C ++行移植到C:

trt__Capabilities *capabilities = ctx->getMediaServiceCapabilities(this->soap);
tds__GetServicesResponse.Service.back()->Capabilities->__any = soap_dom_element(this->soap, NULL, "trt:Capabilities", capabilities, capabilities->soap_type());

我认为这样做会但是在C gSOAP API中不能像这样使用soap_dom_element

tds__GetServicesResponse->Service[1].Capabilities->__any = soap_dom_element(soap, NULL, "trt:Capabilities", capabilities, SOAP_TYPE__tds__Service_Capabilities);

我试过的另一件事是编译但在运行时崩溃

struct trt__Capabilities *capabilities = fillServiceCapabilities(ctx, soap);
char * tag = "trt:Capabilities";
char * type = "";
int id = -1;
soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, capabilities, 
    SOAP_TYPE_trt__Capabilities), type);
void * elt =  soap_element_end_out(soap, tag);
soap_add_elt(&tds__GetServicesResponse->Service[1].Capabilities->__any, elt);

请有人帮我找到创建新dom元素的正确方法,并将其分配给“struct soap_dom_element __any”对象。

谢谢!

c gsoap
1个回答
1
投票

您只需将__any成员设置为使用soap_elt_new的动态分配的DOM节点即可:

tds__GetServicesResponse->Service[1].Capabilities->__any = soap_elt_new(soap, NULL, "trt:Capabilities”);

然后将此DOM节点的可序列化“节点”和“类型”值设置为capabilities类型的可序列化C tds__Service_Capabilities数据:

soap_elt_node(tds__GetServicesResponse->Service[1].Capabilities->__any, capabilities, SOAP_TYPE__tds__Service_Capabilities);

这将capabilities序列化为元素<trt:Capabilities>

见gsoap C DOM API documentation

编辑:我的意思是soap_elt_node而不是soap_dom_node如上所述。

© www.soinside.com 2019 - 2024. All rights reserved.