[Ext] Re: [xsd-users] DLLs and --generate-element-type
--generate-element-map
Nicolas Weidmann
n.weidmann at lombardodier.com
Tue Jul 14 02:10:46 EDT 2026
Hi Boris,
Here the test XSD and XML documents I use to validate my intermediate library:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.acme.corp/test"
targetNamespace="http://www.acme.corp/test"
xmlns:tns="http://www.acme.corp/test"
elementFormDefault="qualified">
<!-- Top Level Base Type -->
<xs:complexType name="Fidget">
<xs:attribute name="Name" type="xs:string" use="required" />
<xs:attribute name="ModelNumber" type="xs:string" use="required" />
</xs:complexType>
<!-- ACME Compliant Useful Sub-Fidget -->
<xs:complexType name="SubFidget">
<xs:complexContent>
<xs:extension base="Fidget">
<xs:sequence>
<xs:element name="PrimaryFunction" type="xs:string" />
<xs:element name="BackfireTrigger" type="xs:string" />
<xs:element name="ExplosionRadiusFeet" type="xs:integer" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Polymorphic Root Element -->
<xs:element name="AcmeProduct" type="Fidget" />
</xs:schema>
The first test document and test that works:
<?xml version="1.0" encoding="UTF-8"?>
<acme:AcmeProduct xmlns:acme="http://www.acme.corp/test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Name="Standard Pocket-Pinnacle Fidget"
ModelNumber="ACME-1000-BASE" />
TEST_F(ExtensionsTest, parseFidget)
{
try {
const auto prod = parse<test::AcmeProduct>(FidgetDocument); // ExtensionsTest helper around xml_schea::ElementMap::parse that passes the XSSD for validation, ...
ASSERT_TRUE(prod);
EXPECT_EQ(prod->getValue().getName(), "Standard Pocket-Pinnacle Fidget");
EXPECT_EQ(prod->getValue().getModelNumber(), "ACME-1000-BASE");
}
catch (const xsd::cxx::tree::exception<char>& ex) {
FAIL() << ex;
}
catch (const std::exception& ex) {
FAIL() << ex.what();
}
catch (...) {
FAIL();
}
}
And the second document that fails (parses only the Fidget part, not the SubFidget...)
<?xml version="1.0" encoding="UTF-8"?>
<acme:AcmeProduct xmlns:acme="http://www.acme.corp/test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="acme:SubFidget"
Name="Self-Destructing Stress Anvil"
ModelNumber="ACME-9942-BOOM">
<acme:PrimaryFunction>Deep pressure finger relaxation</acme:PrimaryFunction>
<acme:BackfireTrigger>Pressing down 5% too hard</acme:BackfireTrigger>
<acme:ExplosionRadiusFeet>40</acme:ExplosionRadiusFeet>
</acme:AcmeProduct>
template<typename T, typename Base, std::enable_if_t<std::is_base_of_v<Base, T>>* = nullptr>
const T* dynamic_extension_cast(const Base* base)
{
return dynamic_cast<const T*>(base);
}
TEST_F(ExtensionsTest, parseSubFidget)
{
try {
const auto prod = parse<test::AcmeProduct>(SubFidgetDocument);
ASSERT_TRUE(prod);
EXPECT_EQ(prod->getValue().getName(), "Self-Destructing Stress Anvil");
EXPECT_EQ(prod->getValue().getModelNumber(), "ACME-9942-BOOM");
const auto* subFidget = dynamic_extension_cast<test::SubFidget>(&prod->getValue());
ASSERT_TRUE(subFidget); // This fails as the above cast returned null even though the xsi:type is "acme:SubFidget"
EXPECT_EQ(subFidget->getPrimaryFunction(), "Deep pressure finger relaxation");
EXPECT_EQ(subFidget->getBackfireTrigger(), "Pressing down 5% too hard");
EXPECT_EQ(subFidget->getExplosionRadiusFeet(), 40);
}
catch (const xsd::cxx::tree::exception<char>& ex) {
FAIL() << ex;
}
catch (const std::exception& ex) {
FAIL() << ex.what();
}
catch (...) {
FAIL();
}
}
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: lundi, 13 juillet 2026 14:53
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:
>
> As soon as I activate --generate-element-type --generate-element-map,
> I can only parse or serialize the element's (top) type.
Ok, I studied the source a bit and it appears we don't support
polymorphism in element types. I believe the reason for this is
that when the root element's type is polymorphic, one would either
have (in XML) the same element represent multiple "instances" via
xsi:type or have multiple elements via the substitution group,
which then can still be all parsed via the base root element in
the generated code.
So I would be curious to know how many root elements you need
to handle and whether they form hierarchies via substitution
groups?
[[ 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