[Ext] Re: [xsd-users] DLLs and --generate-element-type
--generate-element-map
Nicolas Weidmann
n.weidmann at lombardodier.com
Fri Jul 17 09:43:53 EDT 2026
Hi Boris,
I followed your advice and by looking at the code generated without --generate-element-type, I could attempt the following code when --generate-element-type is used (NO --generate-element-map) and it successfully serialized both the a Fidget and a SubFidget (same XSD/XML examples I provided you with a few days ago)
I will try next week, as I am done working at 16h for this week, with parsing and see if it is also possible to adapt the code generated when --generate-element-type is not used.
Have a nice week-end !
Nicolas
NOTE: the _ at the end of the methods is just to remove an ambiguity with existing code. And the code is dirty...
xml_schema::dom::unique_ptr<::xercesc::DOMDocument>
create_document_(const xml_schema::ElementType& element, const xml_schema::Type& value, const xml_schema::NamespaceInfomap& infomap, xml_schema::Flags flags)
{
return xsd::cxx::tree::type_serializer_map_instance<0, char>().serialize(element._name().c_str(), element._namespace().c_str(), infomap, value, flags);
}
xml_schema::dom::unique_ptr<::xercesc::DOMDocument>
create_document_(const xml_schema::ElementType& element, const xml_schema::NamespaceInfomap& infomap, xml_schema::Flags flags)
{
return xsd::cxx::xml::dom::serialize<char>(element._name().c_str(), element._namespace().c_str(), infomap, flags);
}
template<typename T, std::enable_if_t<std::is_base_of<xml_schema::ElementType, T>::value, int> = 0>
void serialize_(std::ostream& stream,
const T& element,
const xml_schema::NamespaceInfomap& infomap = {},
const char* encoding = "UTF-8",
xml_schema::Flags flags = 0)
{
const auto& value = element.getValue();
const bool isBaseType = (typeid(typename T::ValueType) == typeid(value));
auto document = isBaseType ? create_document_(element, infomap, flags) : create_document_(element, value, infomap, flags);
::xercesc::DOMElement& e = *document->getDocumentElement();
const ::xsd::cxx::xml::qualified_name<char> n(::xsd::cxx::xml::dom::name<char>(e));
if (isBaseType) {
if (n.name() == element._name() && n.namespace_() == element._namespace()) {
e << value;
}
else {
throw ::xsd::cxx::tree::unexpected_element<char>(n.name(), n.namespace_(), element._name(), element._namespace());
}
}
else {
xsd::cxx::tree::type_serializer_map_instance<0, char>().serialize(element._name().c_str(), element._namespace().c_str(), e, n, value);
}
::xsd::cxx::xml::dom::ostream_format_target target(stream);
::xsd::cxx::tree::error_handler<char> handler;
if (!::xsd::cxx::xml::dom::serialize(target, *document, std::string{ encoding }, handler, flags)) {
handler.throw_if_failed<::xsd::cxx::tree::serialization<char>>();
}
}
template<typename T, std::enable_if_t<std::is_base_of<xml_schema::ElementType, T>::value, int> = 0>
std::string serialize_(const T& element, const xml_schema::NamespaceInfomap& infomap = {}, const char* encoding = "UTF-8", xml_schema::Flags flags = 0)
{
std::ostringstream stream;
serialize_(stream, element, infomap, encoding, flags);
return stream.str();
}
Nicolas Weidmann
Banque Lombard Odier & Cie SA
Rue de la Corraterie 11 - 1204 Genève - Suisse
T +41 22 709 23 17
www.lombardodier.com
-----Original Message-----
From: Boris Kolpackov <boris at codesynthesis.com>
Sent: vendredi, 17 juillet 2026 12:12
To: Nicolas Weidmann <n.weidmann at lombardodier.com>
Cc: xsd-users at codesynthesis.com
Subject: Re: [Ext] Re: [xsd-users] DLLs and --generate-element-type --generate-element-map
Nicolas Weidmann <n.weidmann at lombardodier.com> writes:
> A ADL serialize for a future release of XSD ? Or parse/serialize traits ?
I think if we decide to support this, the most sensible way would be to
just fix the element types feature to support polymorphism. I've filed
an issue to track this:
https://github.com/codesynthesis-com/xsd/issues/3
> In order to make life more simpler for me, I am planning to write a
> small app that will scan the XSDs for root elements and will create
> the helpers I need based on the different parseMyObject / serializeMyObject.
BTW, I think you could implement your own parsing with support for
polymorphism for element maps non-invasively. We generate public
static functions that return the element name and namespace and
the element's type alias is also available. So you could implement
your helper parse() template to do as polymorphism-supporting parsing
functions do instead of calling the element types' from DOMElement
constructor.
The same approach should work for serialization.
[[ rethink everything. ]]<https://www.lombardodier.com>
[[LinkedIn]]<https://www.linkedin.com/company/lombard-odier> [[Twitter]] <https://twitter.com/lombardodier> [[Facebook]] <https://facebook.com/lombardodier> [[Instagram]] <https://www.instagram.com/lombardodier/> [[YouTube]] <https://www.youtube.com/channel/UCqatbeqXskmWejbm0KPLV3w>
*** IMPORTANT NOTICE REGARDING INSTRUCTIONS by EMAIL ***
Please be aware that instructions received by e-mail should be
considered delayed and not executed unless they have been
specifically confirmed by your relationship manager/banker.
Email traffic during turbulent times in the financial markets is
high and cannot always be acted upon at all times.
Lombard Odier cannot be held liable for such delay in execution
or for the non-execution of an instruction given by email even
if it was given in due time. Therefore, instructions requiring
immediate action must be communicated by telephone by calling
the bank’s registered landline.
Thank you for your understanding.
*** IMPORTANT INFORMATION ABOUT DATA PROTECTION ***
You might be receiving this because you have provided us with
your contact details. If this is the case note that we may process
your personal data for direct marketing purposes.
If you wish to object to this processing, please notify the
Group’s Data Protection Officer<mailto:group-dataprotection at lombardodier.com>.
For more information: www.lombardodier.com/privacy-policy
DISCLAIMER **********************************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by any company
of the Lombard Odier group. If you are not the intended
recipient of this message, kindly notify the sender
immediately and destroy this message. Thank You.
*******************************************************(dch)*
More information about the xsd-users
mailing list