Load and parse XMI file with EMF
<p>I need to load and parse the xmi file(version: OMG XMI 2.4.1) by EMF, but now get stuck.</p>

<p>In <a href="http://www.omg.org/spec/XMI/2.4.1/" rel="nofollow noreferrer">OMG XMI Spec 2.4.1</a>, there is a XMI schema <strong>XMI.xsd</strong>, and a <strong>XMI-model.xmi</strong>. So here for instance, I need to load and parse <strong>XMI-model.xmi</strong> by EMF.</p>

<p>What I have done as follow:</p>

<ul>
<li>New an EMF project in Eclipse</li>
<li>Import xmi schema: <strong>XMI.xsd</strong>, and get an <strong>xmi.genmodel</strong> file </li>
<li>Use <strong>xmi.genmodel</strong> to generate all code in eclipse, it will generate the model code</li>
<li><p>New a Junit4 test case and try to load the <strong>XMI-model.xmi</strong> file with <strong>Junit plug-in test</strong> but failed, following is my code.</p>

<pre><code>@Test
public void test() throws IOException {
    URI uri = URI
            .createFileURI("/home/pzhengshuai/Desktop/15Feb-19Feb/XMI-model.xmi");
    _20110701ResourceFactoryImpl factory = new _20110701ResourceFactoryImpl();
    Resource resource = factory.createResource(uri);
    Map&lt;String, Boolean&gt; options = new HashMap&lt;String, Boolean&gt;();
    options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
    resource.load(options);
    EObject model = (EObject) resource.getContents().get(0);
    Assert.assertNotNull(model);
}
</code></pre></li>
</ul>

<p>The exception is:</p>

<pre><code>org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'XMIType' not found. (file:/home/pzhengshuai/Desktop/15Feb-19Feb/XMI-model.xmi, 2, 164)
</code></pre>

<p>Okay, then I tried to read the xsd file and xmi file, I found there is a namespace <code>xmlns:uml="http://www.omg.org/spec/UML/20110701"</code> inside the <strong>XMI-model.xmi</strong>, so I went to the link of the uml space and tried to found the schema of UML. Unfortunately, in this link, all the files about the UML is en format XMI.</p>

<p>So I tried two more option:</p>

<ol>
<li>try to convert <strong>UML.xmi</strong> to <strong>UML.xsd</strong> by using Enterprise Architect, and Altova XMLspy, and do the same stuff above, Failed. Personally, I think this convertion may lost some information.</li>
<li>I found a similiar question <a href="https://stackoverflow.com/questions/17967112/xsd-for-xmi-2-1-1">here</a>, </li>
</ol>

<blockquote>
  <p>You can find the XMI XSD on the OMG website XMI XSD 2.1.1 but you will also need the UML Schema and the MOF Schema.
  A better way to read and write UML XMI files is to use the Eclipse UML implementation. It can easily be used outside Eclipse in a simple Java program : see</p>
</blockquote>

<p>I followed the answer and read the documentation about Eclipse UML implementation, but I thought it is not what I want exactly.</p>

<p>So I hope some one could give me some advices. Thanks in advance for help!</p>