Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to save UML2 model as XMI (standalone)
How to save UML2 model as XMI (standalone) [message #476832] Mon, 07 January 2008 23:33 Go to next message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

When I save my Model (from a standalone Java app) I don't get the top level
xmi:XMI element. Instead, the uml:Model element is at the top level.

I've tried using both .xmi and .uml extensions. (Interesting differences
result, but this isn't one of them).

My code is this:
public void save(Model model, String pathName) {
URI uri = URI.createURI("file:///" + pathName.replace('\\', '/'));
ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Ecore2XMLResource.FILE_EXTENSION,
Ecore2XMLResource.Factory.INSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(XMI2UMLResource.FILE_EXTENSION,
XMI2UMLResource.Factory.INSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Resource resource = resourceSet.createResource(uri);
resource.getContents().add(model);
try {
resource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}

Obviously I've tried to mash together all the examples in the documentation
and what I've found in this newsgroup, but I'm still not getting it.
Re: How to save UML2 model as XMI (standalone) [message #476833 is a reply to message #476832] Tue, 08 January 2008 14:13 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Jeff,

Note that the 'XMI' pseudo element is optional in XMI - it's only really
needed if there is more than one "real" root in the document. If you are
using the UML resource implementation, I assume what's happening is your
resource only contains one root (the model), and so the 'XMI' element is not
required...

Kenn

"Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
news:flucsb$76l$1@build.eclipse.org...
> When I save my Model (from a standalone Java app) I don't get the top
> level xmi:XMI element. Instead, the uml:Model element is at the top level.
>
> I've tried using both .xmi and .uml extensions. (Interesting differences
> result, but this isn't one of them).
>
> My code is this:
> public void save(Model model, String pathName) {
> URI uri = URI.createURI("file:///" + pathName.replace('\\', '/'));
> ResourceSetImpl resourceSet = new ResourceSetImpl();
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Ecore2XMLResource.FILE_EXTENSION,
> Ecore2XMLResource.Factory.INSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(XMI2UMLResource.FILE_EXTENSION,
> XMI2UMLResource.Factory.INSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(model);
> try {
> resource.save(null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
> Obviously I've tried to mash together all the examples in the
> documentation and what I've found in this newsgroup, but I'm still not
> getting it.
>
Re: How to save UML2 model as XMI (standalone) [message #476836 is a reply to message #476833] Tue, 08 January 2008 16:59 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

Kenn,

Interesting, and apparently even true in the "interoperability" sense of
being needed.

Thanks, Jeff
Re: How to save UML2 model as XMI (standalone) [message #625857 is a reply to message #476832] Tue, 08 January 2008 14:13 Go to previous message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
Jeff,

Note that the 'XMI' pseudo element is optional in XMI - it's only really
needed if there is more than one "real" root in the document. If you are
using the UML resource implementation, I assume what's happening is your
resource only contains one root (the model), and so the 'XMI' element is not
required...

Kenn

"Jeff Lansing" <jlansing@spawar.navy.mil> wrote in message
news:flucsb$76l$1@build.eclipse.org...
> When I save my Model (from a standalone Java app) I don't get the top
> level xmi:XMI element. Instead, the uml:Model element is at the top level.
>
> I've tried using both .xmi and .uml extensions. (Interesting differences
> result, but this isn't one of them).
>
> My code is this:
> public void save(Model model, String pathName) {
> URI uri = URI.createURI("file:///" + pathName.replace('\\', '/'));
> ResourceSetImpl resourceSet = new ResourceSetImpl();
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(Ecore2XMLResource.FILE_EXTENSION,
> Ecore2XMLResource.Factory.INSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(XMI2UMLResource.FILE_EXTENSION,
> XMI2UMLResource.Factory.INSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(model);
> try {
> resource.save(null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
> Obviously I've tried to mash together all the examples in the
> documentation and what I've found in this newsgroup, but I'm still not
> getting it.
>
Re: How to save UML2 model as XMI (standalone) [message #625860 is a reply to message #476833] Tue, 08 January 2008 16:59 Go to previous message
Eclipse UserFriend
Originally posted by: jlansing.spawar.navy.mil

Kenn,

Interesting, and apparently even true in the "interoperability" sense of
being needed.

Thanks, Jeff
Previous Topic:Re: How do I model with UML 2 in eclipse?
Next Topic:Problems about loading UML file
Goto Forum:
  


Current Time: Fri Apr 19 19:13:28 GMT 2024

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

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

Back to the top