Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » SOS Please help me: EMF XMI Serialization(How can I create a root element to put all my element under the root element)
SOS Please help me: EMF XMI Serialization [message #532777] Tue, 11 May 2010 04:36 Go to next message
Eclipse UserFriend
Hi,
can somebody explain me how I can create a XMI root element in my code to put all elements under this root element.

Thanks in advance!

Here is the sample code:

public class SerializationUtility {

public void serialize() throws IOException {

ResourceSet rs = new ResourceSetImpl();

XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
myXMResourceImpl.getDefaultSaveOptions().put( XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);

// Register the base XML resource factory implementation in the local resource factory registry.
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut( "xmi", new XMIResourceFactoryImpl());
URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");

Resource resource = rs.createResource( fileURI);
// add the root objects to the resource
Iterator<ComputerResources> itr = ComputerCollectionGenerator.computerResoucres.iterator();
while ( itr.hasNext()) {
ComputerResources next = itr.next();
resource.getContents().add( next);
}

resource.save( null);

}
}

[Updated on: Tue, 11 May 2010 05:56] by Moderator

Re: EMF XMI Serialization [message #532853 is a reply to message #532777] Tue, 11 May 2010 07:17 Go to previous messageGo to next message
Eclipse UserFriend
Ugar,

If the resource's contents contain multiple elements, there will be an
XMI root element to hold them all. Otherwise, the one element in the
contents will be used as the root.


Ugur Kocak wrote:
> Hi,
> can somebody explain me how I can create a XMI root element in my code
> to put all elements under this root element.
>
> Thanks in advance!
>
> Here is the sample code:
>
> public class SerializationUtility {
>
> public void serialize() throws IOException {
>
> ResourceSet rs = new ResourceSetImpl();
>
> XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
> myXMResourceImpl.getDefaultSaveOptions().put(
> XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
>
> // Register the base XML resource factory implementation in the
> local resource factory registry.
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> "xmi", new XMIResourceFactoryImpl());
> URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");
>
> Resource resource = rs.createResource( fileURI);
> // add the root objects to the resource
> Iterator<ComputerResources> itr =
> ComputerCollectionGenerator.computerResoucres.iterator();
> while ( itr.hasNext()) {
> ComputerResources next = itr.next();
> resource.getContents().add( next);
> }
>
> resource.save( null);
>
> }
> }
>
Re: EMF XMI Serialization [message #532877 is a reply to message #532853] Tue, 11 May 2010 08:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

thank you for the hint.

Best regards
Ugur
Re: EMF XMI Serialization [message #622880 is a reply to message #532853] Tue, 11 May 2010 08:58 Go to previous message
Eclipse UserFriend
Hi Ed,

thank you for the hint.

Best regards
Ugur
Previous Topic:EMF XMI Serialization
Next Topic:[EMF Compare] UpdateReference: leftTarget or rightTarget?
Goto Forum:
  


Current Time: Thu Jul 24 15:40:53 EDT 2025

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

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

Back to the top