Skip to content
ifkarp edited this page May 22, 2015 · 2 revisions

Some code examples to illustrate how to use the Libmei in C++:

Reading in an MEI XML file

#include <mei/xmlimport.h>

mei::XMLImportResult res = mei::documentFromFile("beethoven.mei", mei::MEI_STRICT_IMPORT);
mei::MeiDocument *doc = res.getMeiDocument();

Writing out an XML file

#include <mei/mei.h>
#include <mei/shared.h>
#include <mei/cmn.h>
#include <mei/xmlexport.h>

//create a very basic document structure
mei::MeiDocument *doc = new mei::MeiDocument();
mei::MeiElement *m1 = new mei::MeiElement("mei");

doc->setRootElement(m1);

//create a new note with an attribute
mei::MeiAttribute *att = new mei::MeiAttribute("accid", "s");
mei::Note *n = new mei::Note();
n->addAttribute(att);

m1->addChild(n);

//This will return True if it was successful
bool status = mei::documentToFile(doc, "outputfile.mei")

You can also look at the C++ unit tests code for more examples.