This tutorial explains how you can do code generation with Xtend and Xpand, using XML Schema Definitions as meta models and XML files as models. To keep things easy, the introduced example is a minimalistic one. A text file is generated from contents specified in XML. The general concept of models, meta models and why and when code generation is useful, is not explained. At the end, a deeper view under the hood is taken to understand how XML Schemas are transformed to EMF Ecore models, and which flexibilities/restrictions this approach provides.
All source files listed within this tutorial are also available as
an example project wich can be imported into the Eclipse workspace by
running
"File" / "New" / "Example..." / "Xpand/Xtend Examples
using an XSD Meta Model" / "M2T custom XML to Text via Xpand (minimal
Example)"
. This will create the project
org.eclipse.xpand.examples.xsd.m2t.minimal
project
in your workspace. This minimal example is based on "
M2T custom
XML to Java via Xpand
"
(org.eclipse.xpand.examples.xsd.m2t.xml2javawizard
)
which is more comprehensive and recommended for further reading.
To generate code from XML files with Xpand, at least files of the following four types are needed:
Meta Model ( metamodel.xsd
)
Model ( model.xml
)
Xpand Template ( template.xpt
)
MWE Workflow ( workflow.mwe
)