I am using EMF with an XSD generated ecore. Now I’ve got the propblem, that the generated file isn’t valid.
There are 2 Reasons:
- There is a DocumentRoot element inserted
- The attributes have the wrong capitalization.
The thing is: It is not a problem of the model, it is Propblem of the saving process (since in the EMF generated editor the output is correct.
First the correct result:
<?xml version="1.0" encoding="UTF-8"?>
<model:widgetspecification xmlns:model="http://test.com/model" Description="DESC" Name="NAME">
<model:Property Name="PROP1"/>
<model:Property Name="PROP2/>
</model:widgetspecification>
The actual result:
<?xml version="1.0" encoding="ASCII"?>
<model:DocumentRoot xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:model="http://test.com/model">
<widgetspecification description="DESC" name="NAME">
<property name="PROP1"/>
<property name="PROP2"/>
</widgetspecification>
</model:DocumentRoot>
And finally the save procedure (just output to sysout)
Resource resource = new XMIResourceImpl();
resource.getContents().add(modelRoot);
resource.save(System.out, Collections.EMPTY_MAP);
Sadly I couldn’t find any relevant differences in the saving routines (although of course the EMF generated code is a lot more complicated) – I guess I may have missed s.th. but I still haven’t found anything).
Also interesting is the fact, that the EMF generated file is UTF-8, but I can’t find any reference where this option is set.
Use
XMLResourceinstead ofXMIResourceand setOPTION_EXTENDED_META_DATAto true.