Example: Building and querying plain XML documents with EOL

var library = new t_library;
XMLDoc.root = library;

library.createBook("EMF Eclipse Modeling Framework", 
  List{"Dave Steinberg", "Frank Budinsky", 
    "Marcelo Paternostro", "Ed Merks"}, 
  744, 2009);

library.createBook("Eclipse Modeling Project: " + 
  "A Domain-Specific Language (DSL) Toolkit", 
    List{"Richard Gronback"}, 736, 2009);

library.createBook("Official Eclipse 3.0 FAQs", 
  List{"John Arthorne", "Chris Laffra"}, 432, 2004);

operation Element createBook(title : String, authors : List(String), 
  pages : Integer, published : Integer) {

  // Create a new book element
  var book = new t_book;
  // Set its title
  book.a_title = title;
  // Set its pages
  book.i_pages = pages;
  // Create its author children
  for (author in authors) {
    var authorElement = new t_author;
    authorElement.text = author;
  // Create its published child
  var publishedElement = new t_published;
  publishedElement.text = published;
  // Add the book as a child

// Store all books in a collection variable
var books = t_book.all;

// Print the total number of pages in all books
// Print the titles of books with more than 1 authors
for (book in books) {
  if (book.c_author.size() > 1) {

// Print the title of the book with the most pages
var maxPages = books.collect(b|b.i_pages).max;
books.selectOne(b|b.i_pages = maxPages).a_title.println();

// Print the title of all books written by Ed Merks.
// Demonstrates navigating to the parent node.
for (author in t_author.all) {
  if (author.text = "Ed Merks") {

// Print the tag and text of all children 
// of each book (author + published)
for (book in books) {
  for (child in book.children) {
    (child.tagName + "->" + child.text).println();
<project default="main">
  <target name="main">
    <epsilon.xml.loadModel name="XMLDoc" file="gen_library.xml" 
      read ="false" store="true"/>
    <epsilon.eol src="builddocument.eol">
      <model ref="XMLDoc"/>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  <book title="EMF Eclipse Modeling Framework" pages="744">
    <author>Dave Steinberg</author>
    <author>Frank Budinsky</author>
    <author>Marcelo Paternostro</author>
    <author>Ed Merks</author>
  <book title="Eclipse Modeling Project: A Domain-Specific Language (DSL) Toolkit" pages="736">
    <author>Richard Gronback</author>
  <book title="Official Eclipse 3.0 FAQs" pages="432">
    <author>John Arthorne</author>
    <author>Chris Laffra</author>

Clone Epsilon's Git repository and then:

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register any .ecore metamodels in the org.eclipse.epsilon.examples.plainxml project
  2. right click the .launch file in the org.eclipse.epsilon.examples.plainxml project
  3. select Run as... and click the first item in the menu that pops up

What's this?

In this example, we use the plain XML driver of Epsilon to build and query an XML document that is not backed by a XSD/DTD.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Epsilon Model Generation Language
Epsilon Pattern Language
Combining the Epsilon Languages

Even more examples...

More examples are available in the examples folder of the Git repository.