I am new to GSOAP, so might be missing something obvious here. But I really couldn't find its solution in GSOAP documentations.
I need to know, how do I silently ignore an unknown node in my xml in GSOAP without affecting other nodes.
For example: I have below class
class gsoap_ex
{
int foo;
char bar;
}
and below XML for it:
<gsoap_ex>
<foo>foo_value</foo>
<unknown>unknown_value</unknown>
<bar>bar_value</bar>
</gsoap_ex>
As of now, my gsoap parses the xml till it reaches the unknown node, after that it returns without further parsing it.
print_after_parsing(gsoap_ex *obj)
{
cout<<obj->foo;
cout<<obj->bar;
}
So in my above function it shows the value of foo but value of bar is not set.
How do I achieve it?
You can configure gSOAP to provide a function pointer to deal with unknown elements, and have your function decide what to do with it.
The https://www.cs.fsu.edu/~engelen/soapfaq.html page discusses handling unknown data. The first part of the paragraph is about detecting unexpected data so that you can figure out what to do about the problem; it seems you've already got that covered, so I've just included the sections detailing how to change the behavior of gSOAP.
My code appears to ignore data when receiving SOAP/XML messages. How can I detect unrecognized element tags at run time and let my application fault?
...
Another way to control the dropping of unknown elements is to define the fignore callback. For example:
{ struct soap soap; soap_init(&soap); soap.fignore = mustmatch; // overwrite default callback ... soap_done(&soap); // reset callbacks } int mustmatch(struct soap *soap, const char *tag) { return SOAP_TAG_MISMATCH; // every tag must be handled }
The tag parameter contains the offending tag name. You can also selectively return a fault:
int mustmatch(struct soap *soap, const char *tag) { // all tags in namespace "ns" that start with "login" are optional if (soap_match_tag(soap, tag, "ns:login*")) return SOAP_OK; // every other tag must be understood (handled) return SOAP_TAG_MISMATCH; }
Presumably, you'd want to write such a callback that returns SOAP_OK
for your unexpected data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With