|
Re: Programmatically serialize with Dynamic instance Xmi format [message #414600 is a reply to message #414598] |
Wed, 14 November 2007 13:32 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------070107060602060906000103
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Yann,
I added this to the FAQ:
2.21 How can I ensure that an xsi:schemaLocation is serialized for
my packages?
< http://wiki.eclipse.org/EMF/FAQ#How_can_I_ensure_that_an_xsi :schemaLocation_is_serialized_for_my_packages.3F>
yann davin wrote:
> Hi all,
>
> I have created a xmi instance of my ecore model with the 'dynamic
> instance' menu. Programmatically I read the instance created and copy
> it propertly but when I try to serialize it in a new xmi file, the xmi
> created file doesn't contain the
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and the
> xsi:schemaLocation=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
> fractaladl.ecore"
> present in the instance created with the 'dynamic instance'.
>
> How can I do to add these informations during the serialization ?
>
> Thanks,
>
>
> Xmi file created by the dynamic instance :
> <?xml version="1.0" encoding="ASCII"?>
> <fractaladl:System xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:fractaladl=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"
> xsi:schemaLocation=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
> fractaladl.ecore">
> <definitions>
> <attributes/>
> <interfaces/>
> <components/>
> <components/>
> </definitions>
> </fractaladl:System>
>
> xmi file serialized programmatically without all needed informations...
> <?xml version="1.0" encoding="ASCII"?>
> <fractaladl:System xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:fractaladl=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">
>
> <definitions>
> <attributes/>
> <interfaces/>
> <components/>
> <components/>
> </definitions>
> </fractaladl:System>
>
> --code which loads the xmi file created by the dynamic instance, copy
> it and try to serialize it again--
> EcoreUtil.Copier copier = new EcoreUtil.Copier();
> Collection<EObject> results =
> copier.copyAll(resource.getContents());
> copier.copyReferences();
> modifiedResource.getContents().addAll(results);
>
> // Save the contents of the resource to the file system.
> try
> {
> Map options = new HashMap();
> //options.put(XMIResource.OPTION_SCHEMA_LOCATION,
> Boolean.TRUE);
> //options.put(XMIResource.OPTION_DECLARE_XML,
> Boolean.TRUE);
> //options.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
> modifiedResource.save(options);
> }catch(IOException e){
> System.err.println(e.getMessage());
> }
>
> Yann
--------------070107060602060906000103
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yann,<br>
<br>
I added this to the FAQ:<br>
<blockquote><a
href=" http://wiki.eclipse.org/EMF/FAQ#How_can_I_ensure_that_an_xsi :schemaLocation_is_serialized_for_my_packages.3F"><span
class="tocnumber">2.21</span> <span class="toctext">How can I ensure
that an xsi:schemaLocation is serialized for my packages?</span></a><br>
</blockquote>
<br>
yann davin wrote:
<blockquote cite="mid:fhequr$79v$1@build.eclipse.org" type="cite">Hi
all,
<br>
<br>
I have created a xmi instance of my ecore model with the 'dynamic
instance' menu. Programmatically I read the instance created and copy
it propertly but when I try to serialize it in a new xmi file, the xmi
created file doesn't contain the
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a> and the
<br>
xsi:schemaLocation=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0fractaladl.ecore">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
fractaladl.ecore"</a>
<br>
present in the instance created with the 'dynamic instance'.
<br>
<br>
How can I do to add these informations during the serialization ?
<br>
<br>
Thanks,
<br>
<br>
<br>
Xmi file created by the dynamic instance :
<br>
<?xml version="1.0" encoding="ASCII"?>
<br>
<fractaladl:System xmi:version="2.0"
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns:fractaladl=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"</a>
xsi:schemaLocation=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0fractaladl.ecore">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0
fractaladl.ecore"</a>>
<br>
<definitions>
<br>
<attributes/>
<br>
<interfaces/>
<br>
<components/>
<br>
<components/>
<br>
</definitions>
<br>
</fractaladl:System>
<br>
<br>
xmi file serialized programmatically without all needed informations...
<br>
<?xml version="1.0" encoding="ASCII"?>
<br>
<fractaladl:System xmi:version="2.0"
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:fractaladl=<a class="moz-txt-link-rfc2396E" href=" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0">" http:///www.fractal.ow2.org/fractal/adl/model/fractaladl.eco re/1.0.0"</a>>
<br>
<definitions>
<br>
<attributes/>
<br>
<interfaces/>
<br>
<components/>
<br>
<components/>
<br>
</definitions>
<br>
</fractaladl:System>
<br>
<br>
--code which loads the xmi file created by the dynamic instance, copy
it and try to serialize it again--
<br>
EcoreUtil.Copier copier = new EcoreUtil.Copier();
<br>
Collection<EObject> results =
copier.copyAll(resource.getContents());
<br>
copier.copyReferences();
<br>
modifiedResource.getContents().addAll(results);
<br>
<br>
// Save the contents of the resource to the file system.
<br>
try
<br>
{
<br>
Map options = new HashMap();
<br>
//options.put(XMIResource.OPTION_SCHEMA_LOCATION,
Boolean.TRUE);
<br>
//options.put(XMIResource.OPTION_DECLARE_XML,
<br>
Boolean.TRUE);
<br>
//options.put(XMIResource.OPTION_USE_XMI_TYPE,
Boolean.TRUE);
<br>
modifiedResource.save(options);
<br>
}catch(IOException e){
<br>
System.err.println(e.getMessage());
<br>
}
<br>
<br>
Yann
<br>
</blockquote>
<br>
</body>
</html>
--------------070107060602060906000103--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02897 seconds