import/export mappings are not modular

0
Hi Community. We generate a big XML in our app out of a tree of non-persistable entities. In this XML the same element can appear in different places and have different parents, but its children usually have identicall mapping rules. In the XSD we declare such elements as xs:complexType and reuse then in different places of the XML schema. However, in the Mendix export mapping we have to manually repeat the routine of clicking all the element's children as many times as it may appear in the schema. The number of an element children can be a hundred and the element may appear a dozen of times in the structure. When making a single change we have to repeat this change multiple times. It's error prone.Is there a way to modularize XML export mapping? Ideally, the parent export mapping could refer to the same child export mapping instead of an XML node in the schema. Or is there a way to prevent manual editing of an export mapping and generate it out of some template?
asked
1 answers
0

Hi Ilya,


I think the limitation here is that the reuse is happening at the XSD level, but not at the Mendix Export Mapping level.

Your XSD approach with reusable xs:complexType is perfectly valid. However, when the XSD is used to create an Export Mapping, Mendix treats the selected schema structure as part of that mapping. There isn't currently a mechanism to define a reusable child Export Mapping and reference it from multiple parent Export Mappings.

So if the same complex element occurs in 10 places, the corresponding mapping configuration has to be maintained in those places.

One thing I would consider is to keep the XSD as the single source of truth and avoid modifying the generated mapping XML manually. Mendix expects the export mapping to correspond to the imported XML schema, and the generated XML also has to follow the XSD structure and ordering.

For the specific problem you describe, I would look at reducing the amount of mapping duplication rather than trying to make the mapping itself modular.

For example, if the repeated element has the same structure everywhere, you can:

  • Keep the common structure in the XSD as a reusable complexType.
  • Generate/maintain the Mendix Export Mapping from that schema.
  • Use associations or microflows to consistently retrieve the same child objects.
  • Keep the repeated mapping sections identical so that changes can be applied consistently.

The mapping itself can retrieve objects by association, by microflow, or from the mapping parameter, so the data retrieval logic can be reused even though the visual mapping definition cannot.

Another option, depending on your integration design, is to split the integration into separate exports. Mendix's Export with mapping activity allows you to explicitly select an Export Mapping and pass its required parameter.

But if the requirement is specifically:

Define ElementA → ElementA_Mapping once and then reference that mapping from 10 different parent mappings

then I don't believe Mendix currently provides that as a supported Export Mapping feature.

I would also avoid manually editing the .xml representation of the Export Mapping. It may work temporarily, but it is not a good maintenance approach because the mapping is a model document managed by Studio Pro.

So unfortunately, for a large schema with heavily reused complex types, the XSD can be modular, but the Mendix Export Mapping itself still requires the mapping structure to be defined in each location.

This is one of those cases where the limitation becomes quite noticeable with large XSDs.

answered