Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF object serialization into xml
EMF object serialization into xml [message #622837] Thu, 06 May 2010 13:21 Go to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
Hi I have a problem in serializing my EMF objects to a XML file.
I want to serialize all Objects but my program create a xml file with only one object in it.

Look on my code:

public void serialize() throws IOException {

ResourceSet rs = new ResourceSetImpl();

// Register the base XML resource factory implementation in the local resource factory registry.

rs.getResourceFactoryRegistry().getExtensionToFact oryMap().put( "xml", new XMLResourceFactoryImpl());
URI fileURI = URI.createFileURI( FILE.getAbsolutePath());

Resource resource = rs.createResource( fileURI);
// serialize all ComputerResources objects into xml
Iterator<ComputerResources> itr = ComputerCollectionGenerator.computerResoucres.iter ator();
while ( itr.hasNext()) {
ComputerResources next = itr.next();
resource.getContents().add( next);
}
resource.save( null);

The objects are created and stored at runtime in ArrayList computerResoucres.

What do I have to do?

Thank you in advance
Re: EMF object serialization into xml [message #622838 is a reply to message #622837] Thu, 06 May 2010 13:32 Go to previous message
Cyril Jaquier is currently offline Cyril JaquierFriend
Messages: 80
Registered: July 2009
Member
Hi,

> Hi I have a problem in serializing my EMF objects to a XML file.
> I want to serialize all Objects but my program create a xml file with
> only one object in it.
>

A XMLResource can only contain a single root element. Use a XMIResource
instead.

The easiest way to do it is 1/ register XMIResourceFactoryImpl with the
".xmi" extension and 2/ end your URI with ".xmi". That's it :-)

Regards,
Cyril
Previous Topic:[EMF Compare] Duplicate move detection
Next Topic:EMF Compare NPE
Goto Forum:
  


Current Time: Thu Apr 25 16:26:24 GMT 2024

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

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

Back to the top