Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsSOS Please help me: EMF XMI Serialization
https://www.eclipse.org/forums/index.php/mv/msg/167961/532777/#msg_532777
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);
}
}
]]>Ugur Kocak2010-05-11T08:36:53-00:00Re: EMF XMI Serialization
https://www.eclipse.org/forums/index.php/mv/msg/167961/532853/#msg_532853
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 Merks2010-05-11T11:17:42-00:00Re: EMF XMI Serialization
https://www.eclipse.org/forums/index.php/mv/msg/167961/532877/#msg_532877
thank you for the hint.
Best regards
Ugur]]>Ugur Kocak2010-05-11T12:58:37-00:00Re: EMF XMI Serialization
https://www.eclipse.org/forums/index.php/mv/msg/167961/622880/#msg_622880
thank you for the hint.
Best regards
Ugur]]>Ugur Kocak2010-05-11T12:58:40-00:00