c++xmlxsdxml-parsingcodesynthesis

Getting C++ object from xsd:extension


I am using the xsd to c++ compiler from codesynthesis. I am compiling these xsd snippets:

<xsd:complexType name="elementBaseType">
    <xsd:sequence>
        <xsd:element name="init" type="initElementType"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="BUTTON_ELEMENT">
    <xsd:complexContent>
        <xsd:extension base="elementBaseType">
            <xsd:sequence>
                <xsd:element name="imageClicked" type="xsd:string"/>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

In my c++-code, I can get all the information of the elementBaseType. But I need the information from my specialized BUTTON_ELEMENT, too. I logged the parsing step and it seem like the constructor of BUTTON_ELEMENT is never called. However, for each BUTTON_ELEMENT in my XML file, the elementBaseType constructor is called.

Am I missing something? I use this command to generate the c++ files:

cxx-tree --std c++11 --generate-polymorphic --output-dir C:/generated Configuration.xsd

Solution

  • You most probably miss the --polymorphic-type command line option.

    Here is a quote from the CodeSynthesis XSD/Tree Manual:

    "However, if your XML vocabulary is not using substitution groups or if substitution groups are defined in a separate schema, then you will need to use the --polymorphic-type option to specify which types are polymorphic."

    Read more details about the --polymorphic-type command line option here:

    CodeSynthesis XSD/Tree command line options