Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » ecore package with multiple namespaces
icon5.gif  ecore package with multiple namespaces [message #760090] Thu, 01 December 2011 09:48 Go to next message
Markus Stier is currently offline Markus StierFriend
Messages: 12
Registered: July 2009
Junior Member
Hi!

I'm new to EMF and could not find an answer to this supposedly simple question:

I want to create XML files using ecore editors.
The resulting XML structure will use multiple namespaces across the elements and attributes.

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<n1:Container xmi:version="2.0" xmlns:xmi="www.omg.org/XMI" xmlns:n1="my.namespace1/1.0" xmlns:n2="my.namespace2/1.0" xmlns:n3="my.namespace3/1.0">
<n1:ElementA n2:Attr1="yes" n3:Attr2="look here!">
<n1:ElementB n1:Attr1="123" n2:Attr1="no">
</n1:ElementB>
</n1:ElementA>
</n1:Container>

I've designed a package with namespace n1 which contains all the elements above. I created code and editors and stuff came out in namespace n1 as expected.
Then I tried to add an attribute in namespace n2. I've defined the Namespace property in Extended Metadata but this namespace is completely ignored in output.

Any suggestions?

Best
Markus


Re: ecore package with multiple namespaces [message #760100 is a reply to message #760090] Thu, 01 December 2011 10:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31548
Registered: July 2009
Senior Member
Markus,

Comments below.

On 01/12/2011 10:48 AM, Markus Stier wrote:
> Hi!
>
> I'm new to EMF and could not find an answer to this supposedly simple
> question:
>
> I want to create XML files using ecore editors. The resulting XML
> structure will use multiple namespaces across the elements and
> attributes.
Whenever you have a certain XML structure you want to achieve, the best
approach is generally to write an XML Schema for it and generate the
model from that...
>
> Sample:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <n1:Container xmi:version="2.0" xmlns:xmi="www.omg.org/XMI"
> xmlns:n1="my.namespace1/1.0" xmlns:n2="my.namespace2/1.0"
> xmlns:n3="my.namespace3/1.0">
> <n1:ElementA n2:Attr1="yes" n3:Attr2="look here!">
> <n1:ElementB n1:Attr1="123" n2:Attr1="no">
> </n1:ElementB>
> </n1:ElementA>
> </n1:Container>
>
> I've designed a package with namespace n1 which contains all the
> elements above.
Typically a separate package is needed per namespace because namespaces
map to EPackage nsURIs.
> I created code and editors and stuff came out in namespace n1 as
> expected. Then I tried to add an attribute in namespace n2. I've
> defined the Namespace property in Extended Metadata but this namespace
> is completely ignored in output.
Are you using the appropriate options to save and load? E.g.,
OPTION_EXTENDED_META_DATA
> Any suggestions?
>
> Best
> Markus
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ecore package with multiple namespaces [message #760113 is a reply to message #760100] Thu, 01 December 2011 11:02 Go to previous messageGo to next message
Markus Stier is currently offline Markus StierFriend
Messages: 12
Registered: July 2009
Junior Member
Ed,

this was the missing link. Thank you very much.

I've changed the following methods in the generated editor according to http..//rodion-en.blogspot.com/2009/03/emf-editors-generate-xml-files-without.html and now my XML contains my namespaces.
Abbreviated description of changes:

in method createModel():
replace
resource = editingDomain.getResourceSet().getResource(resourceURI, true);

with
resource = editingDomain.getResourceSet().createResource(resourceURI);
Map loadOptions = new HashMap();
loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
resource.load(loadOptions);

in method doSave(IProgressMonitor progressMonitor):
add
saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, true);

below
saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

One thing remains:
If I export my ecore model with the _XML Schema_ exporter, my namespaces are used as expected. The _XML Schema for XMI_ exporter ignores the additional namespaces.

Best
Markus


Re: ecore package with multiple namespaces [message #760126 is a reply to message #760113] Thu, 01 December 2011 12:02 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31548
Registered: July 2009
Senior Member
Markus,

Comments below.

On 01/12/2011 12:02 PM, Markus Stier wrote:
> Ed,
>
> this was the missing link. Thank you very much.
>
> I've changed the following methods in the generated editor according
> to
> http..//rodion-en.blogspot.com/2009/03/emf-editors-generate-xml-files-without.html
> and now my XML contains my namespaces. Abbreviated description of
> changes:
>
> in method createModel():
> replace
> resource = editingDomain.getResourceSet().getResource(resourceURI, true);
>
> with
> resource = editingDomain.getResourceSet().createResource(resourceURI);
> Map loadOptions = new HashMap();
> loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
> resource.load(loadOptions);
> in method doSave(IProgressMonitor progressMonitor):
> add saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
Better would be to specialize the resource factory and add these options
to the implementation...
>
> below
> saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,
> Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
>
> One thing remains:
> If I export my ecore model with the _XML Schema_ exporter, my
> namespaces are used as expected. The _XML Schema for XMI_ exporter
> ignores the additional namespaces.
XMI schemas are essentially useless noise in my opinion. That exporter
was written long ago and doesn't take extended meta data into account...
>
> Best Markus
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF4NET] Project status?
Next Topic:[EMFatic] Read attribute of current selected node in canvas
Goto Forum:
  


Current Time: Sun Oct 25 20:00:40 GMT 2020

Powered by FUDForum. Page generated in 0.01666 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top