[xsd-users] DLLs and --generate-element-type --generate-element-map

Boris Kolpackov boris at codesynthesis.com
Tue Jun 30 10:10:39 EDT 2026


Nicolas Weidmann <n.weidmann at lombardodier.com> writes:

> I wanted to use --generate-element-type --generate-element-map in
> order to have a single parse & serialize as our code heavily relies
> on templates and parseMyType, etc. are not generic.
> 
> It works fine as long as all the libs are static, but I need to have
> the different data-binding libraries to be DLLs.
> 
> In that case, it fails as the different dlls have their own element
> map and the application code has its own, empty, element map.
> 
> Do I have to implement my own --custom-type for the element map?

No, the overall approach is to have a "root" DLL that exports the
single map that everyone else imports. The element map is a class
template (with a static data member which is the actual map) and
exporting templates from DLLs is a murky business. If you want
to give it a go, the starting point would be to generate the
header for XML Schema built-in types (which includes the
element_map) and export it from your root DLL. Something along
these lines:

xsd cxx-tree \
  --generate-element-map \
  --generate-element-type \
  --export-xml-schema \
  --export-symbol XML_SCHEMA_EXPORT \
  --generate-xml-schema  \
  xml-schema.xsd

You would need to define XML_SCHEMA_EXPORT appropriately. You will also
need to have this header included in at least one source file that belongs
to the root DLL in order to have the template instantiations exported.

Once this is done, all your actual schemas would be compiled with
--extern-xml-schema in order to use this shared header.



More information about the xsd-users mailing list