我试图用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”对象。
谢谢!
您只需将__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
如上所述。