}}
Concepts are described in W3C XML Recommendation (document and logical structures sections). Concepts for Document Types Declarations are not managed here. Note : there is no composite 'ownedAttribute' reference between Element and Attribute type to avoid ambiguous duplicate owning possibilities considering 'chidren' reference.
The goal of the Generic XML Discoverer plug-in is to allow generic extractions of XML information from a XML file, without the need for a metamodel dedicated to a conforming Document Type Definition(DTD) or XML Schema Description (XSD).
Considering XML files conforming to DTD or XSD, it will be more convenient to have some dedicated metamodels to manipulate information. However, Generic XML Discoverer is an alternative for miscellaneous XML files (no or uncommon DTD/XSD).
This plug-in aims at analyzing any XML file providing a model describing the information found, conforming to the Generic XML metamodel. Moreover, it allows to serialize the xml file back from the model. Thus, some M2M transformations might be used jointly to upgrade some xml files.
Since the metamodel is a subset of W3C XML concepts, the end user should be aware of some limitations in serializing back some advanced XML contents.
Right-click on a XML file and select the XML discoverer ( Discovery > Discoverers > Discover XML Model...):
A discovery parameters dialog opens to let you specify the parameters of the discovery:
Once launched, a progress dialog will appear as soon as the operation begins. Depending on the size of your file, the reverse engineering process might take some time to complete:
At the end of the process, the newly created model file is added to the root of your project if you set SERIALIZE_TARGET to true:
And the model is opened in the default model browser if you selected Open model in editor after discovery:
The model file for the XML file (with a filename ending in "_xml.xmi" by convention) can be opened in any model browser:
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: <source lang="java"> 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(); </source>
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.
You can install the XML discoverer and associated metamodel from the MoDisco update site.
All of the source code is stored in the Eclipse public source repository:
This document is maintained in a collaborative wiki. If you wish to update or modify this document please visit http://wiki.eclipse.org/MoDisco/Components/XML/Documentation/0.9