Export UML do XMI
Formát výmeny, ktorým podľa vlastných slov hovorí každý UML nástroj, a poctivý opis toho, ktorá polovica vášho modelu cestu prežije.
6 min čítaniaXMI 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é otázky
Na čo sa XMI používa?
Na presun UML modelu medzi nástrojmi, ktoré nezdieľajú formát súboru. Je to XML serializácia metamodelu UML, takže nesie model - triedy, atribúty, operácie a vzťahy - a nie jeho obrázok.
Prečo sa pri importe XMI stratí rozloženie diagramu?
Pretože výmena diagramov bola väčšinu života XMI voliteľnou súčasťou štandardu a nástroje si medzeru vyplnili vlastnými rozšíreniami. Prvky dorazia; súradnice, ktoré ich umiestnili na plátno, boli napísané v nárečí, ktoré prijímajúci nástroj nečíta.
Oplatí sa XMI vôbec exportovať?
Áno, keď potrebujete presunúť model. Pre model je to jediná možnosť nezávislá od dodávateľa a znovu rozložiť diagram je práca na popoludnie, kým prepísať štyristo tried je práca na dva týždne. Ak potrebujete obrázok, exportujte radšej SVG alebo PNG.
Súvisiace články