SOS Please help me: EMF XMI Serialization [message #532777] |
Tue, 11 May 2010 08:36 |
Ugur Kocak 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);
}
}
[Updated on: Tue, 11 May 2010 09:56] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04077 seconds