Xtext: Export model as XMI/XML
<p>I have defined a DSL with Xtext. Let's say it looks like this:</p>

<pre><code>Model:
    components+=Component*
;

Component:
    House | Car
;

House:
    'House' name=ID
    ('height' hubRadius=DOUBLE)? &amp;
    ('width' hubRadius=DOUBLE)?
    'end' 'House'
;

Car:
    'Car' name=ID
    ('maxSpeed' hubRadius=INT)? &amp;
    ('brand' hubRadius=STRING)?
    'end' 'Car'
;
</code></pre>

<p>In the generated Eclipse IDE, which is based on my DSL, I implemented a model. Let's say it looks like the following:</p>

<pre><code>House MyHouse
    height 102.5
    width 30.56
end House

Car MyCar
    maxSpeed 190
    brand "mercedes"
end Car
</code></pre>

<p>I now would like to export that model as an XMI or XML file.</p>

<p>The reason I want to do this is, that I have another workflow, which allows me to change the model parameters on the fly, using an XMI/XML file. So instead of redefining my model, I can just pass the XML/XMI file to the workflow, which does this automatically.</p>

<p>Short example: The DSL allows defining the components <code>House</code> and <code>Car</code>. The <code>House</code> allows the parameters <code>width</code> and <code>height</code>, the <code>Car</code> allows the parameters <code>maxSpeed</code> and <code>brand</code> (see grammar above).</p>

<p>So in my workflow I was talking about, the parameters will be changed with different values. For example the generated XML I am looking for would look like this:</p>

<pre><code>&lt;model&gt;
    &lt;component name='House'&gt;
        &lt;param name='height'&gt;102.5&lt;/param&gt;
        &lt;param name='width'&gt;30.56&lt;/param&gt;
    &lt;/component&gt;
    &lt;component name='Car'&gt;
        &lt;param name='maxSpeed'&gt;190&lt;/param&gt;
        &lt;param name='brand'&gt;mercedes&lt;/param&gt;
    &lt;/component&gt;
&lt;/model&gt;
</code></pre>

<p>How can I export my model as XMI/XML?</p>