Customizing EMF XML Serialization

It’s unfortunately that much documentation on the Eclipse Modeling Framework (EMF) is scattered around the ‘net. After digging through the EMF newsgroups (which are immensely useful, and full of useful information!) and several articles, I pieced together how XML serialization of an Ecore model can be customized using ExtendedMetaData EAnnotations.

EMF ExtendedMetaData Screenshot

However, when saving the model the XMLResource.OPTION_EXTENDED_META_DATA option must be set to true in order for the EAnnotations to be effective. To do this:

Map options = new HashMap();options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
options.put(XMLResource.OPTION_XML_MAP, xmlMap);

Finally, saving the model with the specified XML resource options:

resource.save(options); //Save with the options map

References

Leave a Comment

(required)
(will not be published) (required)