Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF XMI Serialization
EMF XMI Serialization [message #622871] Tue, 11 May 2010 08:36 Go to next message
Ugur Kocak is currently offline Ugur KocakFriend
Messages: 33
Registered: February 2010
Member
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 #622878 is a reply to message #622871] Tue, 11 May 2010 11:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
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);
>
> }
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF Compare Start problem
Next Topic:SOS Please help me: EMF XMI Serialization
Goto Forum:
  


Current Time: Thu Apr 18 20:42:29 GMT 2024

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

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

Back to the top