Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serializing EMF Model with XML - Top Element
Serializing EMF Model with XML - Top Element [message #429722] Thu, 30 April 2009 16:44 Go to next message
Christoph Mayerhofer is currently offline Christoph MayerhoferFriend
Messages: 5
Registered: July 2009
Junior Member
Hi!

Today I tried to serialize my EMF Model to XML. I found out that the
XMLSaveImpl class (which does the work of serialization) writes only the
first object from the XMLResource' contents.

protected Object writeTopObjects(List<? extends EObject> contents)
{
return writeTopObject(contents.get(0));
}

If I add several objects to the XMLResource' contents, only the first
object is serialized.

Is there a best practice how to add a top level object, or do I have to
create a root object in my model?

Regards,
Christoph
Re: Serializing EMF Model with XML - Top Element [message #429766 is a reply to message #429722] Thu, 30 April 2009 17:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Christoph,

Comments below.

Christoph Mayerhofer wrote:
> Hi!
>
> Today I tried to serialize my EMF Model to XML. I found out that the
> XMLSaveImpl class (which does the work of serialization) writes only
> the first object from the XMLResource' contents.
>
> protected Object writeTopObjects(List<? extends EObject> contents)
> {
> return writeTopObject(contents.get(0));
> }
>
> If I add several objects to the XMLResource' contents, only the first
> object is serialized.
>
> Is there a best practice how to add a top level object, or do I have
> to create a root object in my model?
You can use an XMIResource to save multiple roots; it will inject a
"fake" XMI root element to hold the contents. In general of course, XML
only allows one root element, so unless you're happy with an XMI
serialization, yes you'll have to define a root object to hold the
multiple children...
>
> Regards,
> Christoph


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:ecore model with package dependency
Next Topic:Show Ecore Datamodel in editor
Goto Forum:
  


Current Time: Fri Apr 26 23:09:44 GMT 2024

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

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

Back to the top