Ignore unknown XML node element in GSOAP

I'm new to GSOAP, so there might be something obvious here. But I really could not find his solution in the GSOAP docs.

I need to know how I silently ignore an unknown node in my xml in GSOAP without affecting other nodes.

For example: I have a 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> 

At the moment, my gsoap parses xml until it reaches an unknown node, after which it will return without further parsing it.

 print_after_parsing(gsoap_ex *obj) { cout<<obj->foo; cout<<obj->bar; } 

So, in my previous function, this shows the value of foo, but the value of bar is not set.

How do I achieve this?

+7
c ++ gsoap
source share
1 answer

You can configure gSOAP to provide a function pointer to work with unknown elements, and your function will decide what to do with it.

The https://www.cs.fsu.edu/~engelen/soapfaq.html page discusses processing of unknown data. The first part of the paragraph is about detecting unexpected data so that you can figure out what to do with the problem; it seems you already got this, so I just included sections that detail how to change gSOAP behavior.

My code seems to be ignoring data when receiving SOAP / XML messages. How can I detect unrecognized element tags at runtime and application error?

...

Another way to control the removal of unknown elements is to define a 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 name of the deny tag. You can also selectively return an error:

 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 want to write a callback that returns SOAP_OK for your unexpected data.

+2
source share

All Articles