|
EMF - Serialization Issue related to Namespace -
06-25-2010, 12:29 AM
We have an ecore model - which is representation of simple data model. I am trying to serialize this model using the following code.
ResourceSet resourceSet = new ResourceSetImpl();
// Register XML resource factory resourceSet.getResourceFactoryRegistry().getExtens ionToFactoryMap()
.put("xmi", new XMIResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI
.createFileURI(outputFile));
// add the root object to the resource
resource.getContents().add((EObject) obj);
resource.save(null);
The model contains A, B, C has three classifiers. All of them have structural features of simple types (String) - id, name etc. They have references too.
A has a reference 'b' which is of type B and 'c' which is of type C. I have set the namespace as "myexample.com" and prefix - test
All reference - the containment is set to be 'true'. Now when i serialize this xmi (which is containing A) - the xmi that gets written is as follows
<test:A xmi:version="1" xmlns:xmi="" xmlns:test="myexample.com">
<b id="1" name="testb"/>
<c id="1" name="testc"/>
</test:A>
The issue is - only the top element seems to have the namespace prefix, where as all the other elements don't have. Also the default namespace is not showing up in this XMI. The issue is when i consume this xmi in another application as an XML - then element b and c - do not seem to have any namespace associated with it?
How can i get - b and c also to have test prefix (or) a default namespace definition on the xmi as "myexample.com"??
|