|
Re: EMF XMI Serialization [message #622878 is a reply to message #622871] |
Tue, 11 May 2010 11:17 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.01708 seconds