Discoverer API

First, add the following plug-in dependencies to your project ( Require-Bundle in your Manifest.MF):

You can launch the discovery of a XML model from a file programmatically, and get the resulting model:

XMLModelDiscoverer discoverer = new XMLModelDiscoverer();
// you can set some parameters
discoverer.setIgnoreWhitespace(true);
discoverer.setLightweightModel(false);
// launch the discovery
discoverer.discoverElement(xmlFile, monitor);
// get the resulting resource containing the XML model
Resource xmlResource = discoverer.getTargetModel();

To have a monitor to pass to the discoverElement method, you can either call the discoverer in an Eclipse Job, or pass a new NullProgressMonitor if you don't need progress reporting.

Some options can be set for the discovery operation :

The XML content can be serialized back since the model elements are contained in a dedicated org.eclipse.emf.ecore.resource.Resource implementation.

For more details see the java documentation on the XMLModelDiscoverer class.