Ecore supports Model2Model transformation by loading a model serialized using XMI as instances of a user metamodel whose elements are instances of Ecore.
It is occasionally necessary to tweak XML and this could be performed by a Model2Model transformation if
a) the XML technology space is loaded as a model in the model technology space
b) the transformation tool is adjusted to work directly on XML in the XML technology space
The latter is unpleasant and not very scalable to other technology spaces.
I suspected that the former would already be available, but after experimenting with XMLResourceFactoryImpl() and looking at DOM support, it seems not,
EMF provides no XML.ecore to model XML elements in EMF, and no variant SAXParser to create the XML.ecore EObjects directly.
Am I mistaken? Has anyone done this? Is there another way?
You can use org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl to load arbitrary XML. If there are XML Schema's available, those will be used to create corresponding Ecore models that are used to represent the instances. If not, just an org.eclipse.emf.ecore.xml.type.XMLTypeDocumentRoot is created at the root of the resource, and it contains instances of org.eclipse.emf.ecore.xml.type.AnyType, EMF's representation of an XML element, all using demand created metadata. You can read this article for details: