Home Ask Login Register

Developers Planet

Your answer is one click away!

Daniel February 2016

How to map xs:any in EMF Ecore?

I have the following type in an xsd:

<xs:complexType name="VendorSpecificType">
        <xs:any namespace="##any" processContents="skip" maxOccurs="unbounded"/>

I created this type in Ecore:

Ecore type

I tried to inject an xml containing the following tags:

    <Vendor ID="1"/>

But it crashes

org.eclipse.m2m.atl.core.ATLCoreException: Error loading test.xml: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'Vendor' not found.

The code used to inject models in metamodels is tested and working. Even this test.xml is loaded correctly if I remove the Vendor tag.

My question is how to map the xsd any to an ecore type so it can be loaded?


After debugging, it seems that the code I use to inject the model into the ecore model is not complete: the extendedmetadata is always null

// Load in metamodel
IReferenceModel metamodel = modelFactory.newReferenceModel();
injector.inject(metamodel, metamodelPath);

model = modelFactory.newModel(metamodel);
injector.inject(model, modelPath);

How do I tell it to load the metadata?


Daniel February 2016

I added the following line

((EMFModelFactory) modelFactory).getResourceSet().getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

before injecting the metamodel.

It works now!

Post Status

Asked in February 2016
Viewed 1,935 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life