views:

590

answers:

6
+5  Q: 

How to read XMI?

I need to read UML diagrams that are serialized into XMI. Is there any library that would allow me to conveniently read UML XMI - by conveniently I mean having some methods to iterate over classes/packages/methods/attributest etc. in model.

I tried EMF, but I am unable to find any tutorial that would show how to import XMI containing UML. I have also found NSUML/NSMDF but the link to documentation is broken.

+1  A: 

ArgoUML can import XMI to its UML model and generate code for Java, C++, C#, PHP4 and PHP5.

marklai
+1  A: 

Maybe simply have a look at Transforming XMI to HTML. This should help you to get started with XSLT and XMI.

Pascal Thivent
A: 

In order to read XMI/UML using EMF, you will need to find, generate or write ECore model for UML. Once you have one of those, you can generate the in-memory classes for manipulating the UML and leverage the other EMF infrastructure.

But a simpler route may be to use the UML2 infrastructure developed by the Eclipse MDT project. (My guess is that it uses EMF under the hood and that there is an ECore model for UML2 in there somewhere.)

Stephen C
You are correct that the UML2 project is built on top of EMF.
ChrisH
A: 

I don't think what you want exists. All tools importing XMI that I know (including my XMI transformation service: http://modeling-languages.com/content/xmi2-tool-exchanging-uml-models-among-case-tools) work by parsing the whole XMI file and creating the corresponding UML model in main memory. Then you can access to the UML elements by querying the model.

To iterate on the XMI model you can easily use XML libraries to select the pieces of the XMI file you are interested in.

Jordi Cabot
A: 

What you are looking for is the Java specification for JMI (“Java Metadata Interface”), which implements MOF for describing Metadata and XMI for transporting the Metadata.

Unfortunately I am currently looking for implementations of JMI myself and suns JMI page seems to be a bit outdated. The open source implementation by netbeans seems to have been dropped for version 6.

Kissaki
+1  A: 

It depends on the version of UML that you are trying to read. The NSUML package that you found only works with UML 1.3. The NetBeans MetaData Repository (MDR) will read handle UML 1.4 and UML 1.5. It can be used as a standalone library (that's what ArgoUML uses), so you don't need NetBeans. For UML 2.x, I think the Eclipse EMF & UML2 libraries are your only choice. EMF is a dependency, but it's really the UML2 stuff that you want. Like with MDR and NetBeans, you don't need Eclipse. ArgoUML uses the Eclipse libraries for its UML 2.x support.

Tom Morris