Skip to main content



      Home
Home » Modeling » EMF » Serializing EMF Model with XML - Top Element
Serializing EMF Model with XML - Top Element [message #429722] Thu, 30 April 2009 12:44 Go to next message
Eclipse UserFriend
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 13:26 Go to previous message
Eclipse UserFriend
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
Previous Topic:ecore model with package dependency
Next Topic:Show Ecore Datamodel in editor
Goto Forum:
  


Current Time: Sat Jul 12 23:05:12 EDT 2025

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

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

Back to the top