Importing XML with inheritance - Excel Exporter Template Manager

1
I’m trying to create export and import functionality for the Excel Exporter module. Since the domain model contains self-references and  inheritance, it doesn’t export to XML that easily. I’ve created a simplified version of the domain model to have a base for a custom XSD. I’ve also already written the XSD. To the idea is that we convert the real object to the simplified model, than export to XML. In order to import the XML and convert that structure to the real domain model. We have almost everything working except importing some XML with inheritance. Below are the relevant parts of the XSD used. XSD <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.conclusion.nl/excel-exporter-template-manager" xmlns:tns="http://www.conclusion.nl/excel-exporter-template-manager" > <xsd:complexType name="MxSheet"> <xsd:sequence> <!-- MxData_MxSheet --> <xsd:element name="MxDataList"> <xsd:complexType> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element name="MxStatic" type="tns:MxStatic" /> <xsd:element name="MxColumn" type="tns:MxColumn" /> </xsd:choice> </xsd:complexType> </xsd:element> <!-- MxSheet_MxObjectReference --> <xsd:element name="MxObjectReference" minOccurs="0" type="tns:defaultSizedString" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="MxData"> <xsd:sequence> <xsd:element name="Name" type="tns:defaultSizedString"/> <xsd:element name="Status" type="tns:Status" /> <!-- De definities van MxCellStyle hangen primair aan MxTemplate. Daar definieren we ze dan ook We nemen hier slechts de name van het gerefereerde MxCellStyle object op, wat we als key gebruiken. De koppeling tussen het MxData object en de MxCellStyle objecten leggen we na de import in een microflow. --> <!-- MxData_MxCellStyle --> <xsd:element minOccurs="0" name="MxCellStyle" type="tns:defaultSizedString"/> <!-- MxXPath_MxData --> <xsd:element name="MxXPathList" type="tns:MxXPathList" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="MxStatic"> <xsd:complexContent> <xsd:extension base="tns:MxData"> <xsd:sequence> <xsd:element name="ColumnPlace" type="xsd:long"/> <xsd:element name="RowPlace" type="xsd:long"/> <xsd:element name="StaticType" type="tns:StaticType"/> <xsd:element name="AggregateFunction" type="tns:AggregateFunction"/> <!-- MxStatic_MxObjectMember --> <xsd:element name="MxObjectMember" minOccurs="0" type="tns:defaultSizedString"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="MxColumn"> <xsd:complexContent> <xsd:extension base="tns:MxData"> <xsd:sequence> <xsd:element name="ColumnNumber" type="xsd:long"/> <xsd:element name="NameAsHeader" type="xsd:boolean"/> <xsd:element name="ObjectAttribute" type="tns:defaultSizedString" /> <xsd:element name="DataAggregate" type="xsd:boolean"/> <xsd:element minOccurs="0" name="DataAggregateFunction" type="tns:AggregateFunction"/> <xsd:element name="ResultAggregate" type="xsd:boolean"/> <xsd:element minOccurs="0" name="ResultAggregateFunction" type="tns:AggregateFunction" /> <!-- MxStatic_MxColumn --> <xsd:element name="MxStaticList"> <xsd:complexType> <xsd:sequence> <xsd:element name="MxStatic" minOccurs="0" maxOccurs="unbounded" type="tns:MxStatic"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <!-- /Entities --> <xsd:element name="MxTemplate" type="tns:MxTemplate" /> </xsd:schema> Note that both MxColumn and MxStatic use MxData as a base. So basically they both inherit from MxData. The XML produced in a simple example looks like below. XML example <MxDataList> <MxColumn> <Name>Name</Name> <Status>Yes</Status> <MxXPathList> <MxXPath> <Order>0</Order> <RetrieveType>Attribute</RetrieveType> <SubVisible>false</SubVisible> <MxObjectMember>Administration.Account / Name</MxObjectMember> </MxXPath> </MxXPathList> <ColumnNumber>1</ColumnNumber> <NameAsHeader>true</NameAsHeader> <ObjectAttribute>Administration.Account / Name</ObjectAttribute> <DataAggregate>false</DataAggregate> <ResultAggregate>false</ResultAggregate> <MxStaticList/> </MxColumn> <MxColumn> <Name>Active</Name> <Status>Yes</Status> <MxXPathList> <MxXPath> <Order>0</Order> <RetrieveType>Attribute</RetrieveType> <SubVisible>false</SubVisible> <MxObjectMember>Administration.Account / Active</MxObjectMember> </MxXPath> </MxXPathList> <ColumnNumber>2</ColumnNumber> <NameAsHeader>true</NameAsHeader> <ObjectAttribute>Administration.Account / Active</ObjectAttribute> <DataAggregate>false</DataAggregate> <ResultAggregate>false</ResultAggregate> <MxStaticList/> </MxColumn> </MxDataList> This looks fine to me. MxDataList  can contain elements of both MxColumn and MxStatic. However when we import this we only see the first element being imported. That element is of type MxData instead of MxColumn, what I would suspect. Below is a screenshot of the microflow that processe the import. I’ve also included a screenshot of the domain model and the import mapping. Import microflow Import mapping   Domain model
asked
1 answers
2

So using the blog post about XML Choice Elements and XML to Domain mappings I was able to figure it out. The issue is that apparently Mendix needs a an extra object as a parent of the choice. So I've added an extra entity to the domain model and updated the mappings. Below some screenshots to illustrate the changes.

Old domain model

 

Updated domain model

 

Updated import mapping

 

 

 

answered