Exporter UML vers XMI
Le format d'échange que chaque outil UML prétend parler, et le récit honnête de la moitié de votre modèle qui survit au voyage.
6 min de lectureXMI 2.5.11 sur 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
| Element | Notation | What it means |
|---|---|---|
| Classifiers | Reliable | Classes, interfaces, components, actors, use cases - name, stereotype and package placement all arrive. |
| Attributes and operations | Reliable | Including types, visibility and multiplicity. The most valuable half of the file and the half nobody wants to retype. |
| Relationships | Reliable | Associations with both ends, generalizations, realizations and dependencies. |
| Diagram layout | Unreliable | Positions and sizes travel in a vendor extension the receiving tool usually ignores. Expect to re-lay-out. |
| Notes and constraints | Mixed | Comments generally survive; OCL constraints depend on whether both tools parse the same OCL version. |
| Tool-specific data | Lost | Colours, 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
- 01XMI serializes the UML metamodel, so it carries the model and not the picture.
- 02Classifiers, members and relationships transfer reliably between conforming tools.
- 03Layout travels in vendor extensions and usually does not survive - budget for re-layout.
- 04Anything that is not UML - colours, custom fields, requirement links - is not in the file.
- 05Read one exported file in a text editor before you rely on the format.
04Questions fréquentes
À quoi sert XMI ?
À déplacer un modèle UML entre des outils qui ne partagent pas de format de fichier. C'est une sérialisation XML du métamodèle UML : il transporte donc le modèle - classes, attributs, opérations et relations - et non son image.
Pourquoi ma mise en page disparaît-elle à l'import XMI ?
Parce que l'échange des diagrammes est resté une partie optionnelle du standard pendant l'essentiel de la vie de XMI, et les outils ont comblé le manque par leurs propres extensions. Les éléments arrivent ; les coordonnées qui les plaçaient étaient écrites dans un dialecte que l'outil récepteur ne lit pas.
Vaut-il encore la peine d'exporter en XMI ?
Oui, quand ce qu'il faut déplacer est le modèle. C'est la seule option indépendante d'un éditeur pour cela, et remettre un diagramme en page prend un après-midi là où retaper quatre cents classes prend quinze jours. Pour une image, exportez plutôt du SVG ou du PNG.
À lire aussi