Export UML do XMI
Formát výměny, kterým podle vlastních slov mluví každý UML nástroj, a poctivý popis toho, která polovina vašeho modelu cestu přežije.
6 min čteníXMI 2.5.11 z 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.
04Časté dotazy
K čemu se XMI používá?
K přesunu UML modelu mezi nástroji, které nesdílejí formát souboru. Je to XML serializace metamodelu UML, takže nese model - třídy, atributy, operace a vztahy - a ne jeho obrázek.
Proč se při importu XMI ztratí rozvržení diagramu?
Protože výměna diagramů byla většinu života XMI volitelnou součástí standardu a nástroje si mezeru vyplnily vlastními rozšířeními. Prvky dorazí; souřadnice, které je umístily na plátno, byly zapsány v nářečí, které přijímající nástroj nečte.
Vyplatí se XMI vůbec exportovat?
Ano, když potřebujete přesunout model. Pro model je to jediná možnost nezávislá na dodavateli a znovu rozvrhnout diagram je práce na odpoledne, zatímco přepsat čtyři sta tříd je práce na dva týdny. Pokud potřebujete obrázek, exportujte raději SVG nebo PNG.
Související články