Archyno
ExportsModelling practice

Exporting UML to XMI

The interchange format every UML tool claims to speak, and the honest account of which half of your model survives the trip.

6 min readXMI 2.5.11 of 3

01What XMI actually is

XMI is XML Metadata Interchange, and the word doing the work is metadata. It is a mechanical rule for serializing any MOF-based metamodel into XML, and UML is one such metamodel - so an XMI file is your model expressed as elements and attributes that follow the UML metamodel's own structure. A class becomes a packagedElement with xmi:type="uml:Class", its attributes become nested ownedAttribute elements, and a relationship becomes anAssociation with two memberEnd references.

That is the whole idea, and it explains both the strength and the famous weakness. The strength: any tool that implements the UML metamodel can read those elements, because they are not a vendor's invention. The weakness follows immediately - nothing in the UML metamodel says where a class sits on a canvas. Coordinates are not part of what XMI was designed to carry.

02What transfers, and what does not

ElementNotationWhat it means
ClassifiersReliableClasses, interfaces, components, actors, use cases - name, stereotype and package placement all arrive.
Attributes and operationsReliableIncluding types, visibility and multiplicity. The most valuable half of the file and the half nobody wants to retype.
RelationshipsReliableAssociations with both ends, generalizations, realizations and dependencies.
Diagram layoutUnreliablePositions and sizes travel in a vendor extension the receiving tool usually ignores. Expect to re-lay-out.
Notes and constraintsMixedComments generally survive; OCL constraints depend on whether both tools parse the same OCL version.
Tool-specific dataLostColours, custom properties, requirement links, test cases. None of it is UML, so none of it is XMI.

The pattern is worth stating once: XMI carries what UML defines, and nothing else. Every disappointment with the format comes from expecting it to carry something the metamodel never described. That is not a defect in XMI so much as an answer to a question people did not realise they were asking.

03Using it without being surprised

Three habits remove most of the pain. Export a small model first and open the XML in a text editor. Ten minutes reading the file tells you more about what your tool emits than any documentation will, and it is where you discover that the layout is in an extension block near the bottom.

Import into a scratch project, never over a real one. An import that partially matches an existing model is far harder to undo than one that arrives in an empty container you can throw away.

Budget for re-layout rather than hoping. A hundred-class model re-arranged into readable views is a day's work, and it is worth costing that in rather than treating it as a failure when it happens. If you need the pictures to survive exactly, the answer is not XMI - it is a native file format or an image export.

In one line each

  1. 01XMI serializes the UML metamodel, so it carries the model and not the picture.
  2. 02Classifiers, members and relationships transfer reliably between conforming tools.
  3. 03Layout travels in vendor extensions and usually does not survive - budget for re-layout.
  4. 04Anything that is not UML - colours, custom fields, requirement links - is not in the file.
  5. 05Read one exported file in a text editor before you rely on the format.

04Common questions

What is XMI used for?

Moving a UML model between tools that do not share a file format. It is an XML serialization of the UML metamodel, so what it carries is the model - the classes, attributes, operations and relationships - rather than a picture of it.

Why does my diagram layout disappear when I import XMI?

Because diagram interchange was an optional part of the standard for most of XMI's life, and tools filled the gap with their own extensions. The elements arrive; the coordinates that placed them on a canvas were written in a dialect the receiving tool does not read.

Is XMI still worth exporting?

Yes, when the thing you need to move is the model. It is the only vendor-neutral option for that, and re-laying-out a diagram is an afternoon where re-typing four hundred classes is a fortnight. For a picture, export SVG or PNG instead.

All articles