问题
I use gSOAP for XML data binding.
Recently I refactored my XSD files by extracting a common part from two files to a separate third file and then imported it in the first two files. This was a deep and complex element that was refactored out.
In actual code I would like to have a single function that takes an object of gSOAP generated type describing that element and constructs some internal objects.
But for this I would need to have that generated class be stable and same for both final XSD files (so that the function can take a single type). Yet I don't see any way to achieve that.
Is there any solution?
I considered making the function a template based on the fact, that even if generated types are different (in particular because of being in different C++ namespaces) they have the same members and so template should work well. But that requires me to expose implementation which I don't want to do (it is complex correspondingly to the element complexity).
Another approach I tried was to force gSOAP to generated code for both primary XSD files into same C++ namespace so that the code generated for the imported XSD will be considered same. But this leads to link issues since the definitions repeat then.
来源:https://stackoverflow.com/questions/16604243/sharing-generated-code-for-shared-imported-xsd-files