如何使用 C 中的 gSOAP 创建 soap_dom_element 以将其分配给 __any?

How to create a soap_dom_element to assign it to __any with gSOAP in C?

我正在尝试使用 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());

我认为这样做可以,但是 soap_dom_element 不能在 C gSOAP 中这样使用 API

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 成员设置为动态分配的 DOM 节点 soap_elt_new:

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

然后将此DOM节点的可序列化"node"和"type"值设置为tds__Service_Capabilities类型的可序列化Ccapabilities数据:

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