Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: for the plan.

Jump to: navigation, search

Model2Text using Xpand and QVT for Query

Revision as of 22:45, 21 July 2009 by (Talk | contribs) (New page: This is a guide on how to configure and exectue an Xpand template which is using QVT for lookup. What your project will look like: *MyEclipseProject **model ***First.ecore ''...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is a guide on how to configure and exectue an Xpand template which is using QVT for lookup.

What your project will look like:

  • MyEclipseProject
    • model
      • First.ecore (main metamodel)
    • out (folder for output)
      • data.csv (what will be generated)
    • templates
      • first2csv.xpt (transformation from metamodel to csv)
    • test
      • MyClass.xmi (an instance of your metamodel data)
    • generate.xml (ant script that executes temaplte)


Eclipse Galileo. Create a new project with the folder structure defined above (we'll create the files as we trundle along).

Create First.ecore

Right Click on model->new->other->model Name the top level package First. Edit its properties

Name	        First
Ns Prefix	First
Ns URI		http:///First.ecore

Add a subpackage called Second. Edit its properties

Name	        Second
Ns Prefix	First.Second
Ns URI		http:///First/Second.ecore

Create an EClass in package Second called MyClass. Create two EAttributes both of type EString called: attribute1 and attribute2

The ecore editor should look something like this

  • First
    • Second
      • MyClass
        • attribute1 : EString
        • attribute2 : EString

Create MyClass.xmi

Right click on MyClass (in the ecore editor) and select 'Create Dynamic Instance' point it to your test (data) folder and call it MyClass.xmi

The default editor is probably wrong, so close it. Right click on MyClass.xmi and select Open With->'Generic EMF Form Editor'.

Edit My Class's attribute1 and attribute2 and put in some test data. I used First and Second as the data.

Create first2csv.xpt

Right click on templates and select New->Other->xPand Template (GMF-Xpand) Select the templates folder and name it first2csv.xpt.

Paste this text in:

«IMPORT 'http:///First.ecore'»

«DEFINE Main FOR First::Second::MyClass -»
«attribute1», «attribute2»

Now to nudge Eclipse, in the editor window hit (CTRL+SPACE) and Eclipse should ask you "Do you want to add Xtend nature to project test?", heck yeah!

Create generate.xml

Right Click on MyEclipseProject and select New->Other->File and call it generate.xml

Paste this text in:

<?xml version="1.0" encoding="UTF-8"?>
<project name="pmw" default="main" xmlns:zzz="">
	<target name="main">
		<zzz:template name="first2csv::Main" 
				<Metamodel nsURI="http:///First.ecore" location="platform:/resource/MyEclipseProject/model/First.ecore" />

Couple of interesting things to note:

  1. The template name first2csv::Main, first2csv has to match the name of the template we have in our template folder.
  2. The #/ at the end of the inputURI is no typo, we are specifying where in the data go.

Validate Xpand Ant tasks are installed

Under Window->Preferences->ANT, have a look at the runtime node at the tasks tab. In the name column you want to see something like


If you don't, you need to get the org.eclipse.gmf.xpand.ant plugin. You can find it included in the GMF Xpand download, just copy this plugin over and launch eclipse.exe -clean to make sure it picks up the plugin.

Generate data.csv

To run this script, right click on generate.xml select Run as 'Ant Build...'. Select the JRE tab and pick 'Run in the same JRE as the workspace'. Click 'Run'.

Refresh your out folder, you should see data.csv with some data

First, Second

Back to the top