Search code examples
eclipse-emfemfxmiecore

EMF - Convert XML model to XMI


I have created an .ecore and .genmodel metamodel from an .xsd file. I'am trying to create a model instance from an .xml file conforming to .xsd file (and in consequence to .ecore metamodel). How can I achieve this goal?


Solution

  • At the end I just need to change root node name. To achieve this goal you just need to follow the next steps:

    1. At your ecore diagram right click your root node (the equivalent of your root node in your xml file).
    2. Click on create dynamic instance.
    3. Make a test model. This model is an XMI instance.
    4. At the end you just have to change your rood node information for the new one (the one generated in the XMI model).

    In my case I replaced

    /* At XML file */
    
    <featureModel>
    //Here you find the model nodes
    ...
    </ featureModel>
    

    With

    /* XML file converted to XMI file. This file conforms to XSD and ecore model. */
    
    <ide:FeatureModelType [here you will find some attributes]>
    //Here you find the model nodes just as they where defined earlier
    ...
    </ide:FeatureModelType>
    

    Of course this could be made programmatically.