Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » What is the best way to translate an EMF model instance to a standard XML model instance
What is the best way to translate an EMF model instance to a standard XML model instance [message #896135] Tue, 17 July 2012 11:50 Go to next message
Florian B. is currently offline Florian B.Friend
Messages: 21
Registered: July 2012
Location: Hamburg Germany
Junior Member
Hi all, I'm new to this forum and I have a question mentioned above.


I've searched on the net and on several forums, but I could't find a solution yet.

I have an Ecore-EMF model that is specified in a few Ecore XSD files and I have another model, that is specified in standard XSD files. Both models have the same meaning, but other names for entities uesed.

I want to translate the Ecore instance into an instance of the standard xml model.

The problem - I guess - is, that the Ecore Model instance is separeted into a few files, which have "EReferences" to each other, wich are not supported by standard xml.
This references shall be translated into standard ID-REF's, so that it is possible to navigate through this references.

What is the best way to perform this translation?

Any help would be great, cause this is really driving me nuts... Thx
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #896140 is a reply to message #896135] Tue, 17 July 2012 11:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

On 17/07/2012 1:50 PM, Florian B. wrote:
> Hi all, I'm new to this forum and I have a question mentioned above.
>
> I've searched on the net and on several forums, but I could't find a
> solution yet.
> I have an Ecore-EMF model that is specified in a few Ecore XSD files
> and I have another model, that is specified in standard XSD files.
> Both models have the same meaning, but other names for entities uesed.
> I want to translate the Ecore instance into an instance of the
> standard xml model.
Why have both?
> The problem - I guess - is, that the Ecore Model instance is separeted
> into a few files, which have "EReferences" to each other, wich are not
> supported by standard xml.
XML schema has anyURI...
> This references shall be translated into standard ID-REF's, so that it
> is possible to navigate through this references.
If you set EReference.resolveProxies to false, then EMF will use IDs (or
fragment paths to reference them). If you really want IDs, you can set
EAttributes.iD to true on the referenced EClass' attributes.

Note that you can use Export Model... from the GenModel to export a
schema corresponding to your Ecore model
>
> What is the best way to perform this translation?
>
> Any help would be great, cause this is really driving me nuts... Thx


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #896146 is a reply to message #896140] Tue, 17 July 2012 12:11 Go to previous messageGo to next message
Florian B. is currently offline Florian B.Friend
Messages: 21
Registered: July 2012
Location: Hamburg Germany
Junior Member
Hey Ed, thx for the fast reply.
The problem is, I don't have the actual Ecore model, only the corresponding XSD files to that model and some sample instances. I only noticed, that this data model is an Ecore is, due to the Ecore.xsd and the EReferences defined in them.

Sorry, that this wasn't clear in first post!

THX
Flo
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #896148 is a reply to message #896146] Tue, 17 July 2012 12:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Flo,<br>
<br>
Comments below.<br>
<div class="moz-cite-prefix">On 17/07/2012 2:11 PM, Florian B.
wrote:<br>
</div>
<blockquote cite="mid:ju3kpc$659$1@xxxxxxxxe.org" type="cite">Hey
Ed, thx for the fast reply.
<br>
The problem is, I don't have the actual Ecore model, only the
corresponding XSD files to that model and some sample instances. I
only noticed, that this data model is an Ecore is, due to the
Ecore.xsd and the EReferences defined in them.
<br>
</blockquote>
You can create an Ecore model from that XSD.<br>
<blockquote><a
href="http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.emf.doc/tutorials/xlibmod/xlibmod.html">Tutorial:
Generating an EMF Model using XML Schema</a></blockquote>
<blockquote cite="mid:ju3kpc$659$1@xxxxxxxxe.org" type="cite">
<br>
Sorry, that this wasn't clear in first post!
<br>
<br>
THX Flo
<br>
</blockquote>
<br>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #897344 is a reply to message #896148] Mon, 23 July 2012 16:34 Go to previous messageGo to next message
Florian B. is currently offline Florian B.Friend
Messages: 21
Registered: July 2012
Location: Hamburg Germany
Junior Member
Hey,

thx for the advice to create an Ecore Model with xsd files. Smile
I was able to create a model to parse the the ecore instances, without problems.

On the other hand, i tried to create a New Ecore model from the standard XML model I have. It was no problem to create the java code and the editor, described in the how to section works as well.

I now have a problem, while parsing the standard XML instances (the examples are valid against the corresponding XSDs). I am always getting a class not found exeption.

Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'FIBEX' is not found or is abstract. (file:/C:/examples/can/communication.xml, 18, 339)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at test.Reader.main(Reader.java:64)


This is the header of the XML instance i try to parse.

<fx:FIBEX xmlns:can="http: //www.asam.net /xml/fbx/can" xmlns:fx="http: //www .asam.net/xml/fbx" xmlns:ho=" http ://www. asam.net/xml" xmlns:xsi=" ht tp://www. w3.org /2001/XMLSchema-instance" xsi:schemaLocation="http :// www.asam. net/xml/ fbx ../../xml_schema/fibex.xsd http: //www .asam.net/xml /fbx/can  ../../xml_schema/fibex4can.xsd" VERSION="4.0.0">
	<fx:PROJECT ID="projectCAN">

sorry for strange formatting otherwise i couldnt post it.... Sad


this is my Java Code
	ResourceSet resourceSet = new ResourceSetImpl();

	// Register the default resource factory -- only needed for stand-alone!
	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());

	// Register the package -- only needed for stand-alone!
	FbxPackage fbx = FbxPackage.eINSTANCE;
	CanPackage can = CanPackage.eINSTANCE;
	XmlPackage xml = XmlPackage.eINSTANCE;
		
	resourceSet.getPackageRegistry().put(FbxPackage.eNS_URI, FbxPackage.eINSTANCE);
	resourceSet.getPackageRegistry().put(CanPackage.eNS_URI, CanPackage.eINSTANCE);
	resourceSet.getPackageRegistry().put(XmlPackage.eNS_URI, XmlPackage.eINSTANCE);
	
	// Get the URI of the model file. 
	URI fileURI = URI.createFileURI(new File("C:\\examples\\can\\communication.xml").getAbsolutePath());

	// Demand load the resource for this file.		
	Resource resource = resourceSet.getResource(fileURI, true); <-- this is causing the exception


The exception also happens, when I try to parse the generated files from the editor example program.

How does the resourceSet get correct initialized to be able to parse the XMLs?

Thank you very much for your help!

[Updated on: Mon, 23 July 2012 16:40]

Report message to a moderator

Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #897369 is a reply to message #897344] Mon, 23 July 2012 19:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Florian,

Comments below.

On 23/07/2012 6:34 PM, Florian B. wrote:
> Hey,
>
> thx for the advice to create an Ecore Model with xsd files. :) I was
> able to create a model to parse the the ecore instances, without
> problems.
> On the other hand, i tried to create a New Ecore model from the
> standard XML model I have. It was no problem to create the java code
> and the editor, described in the how to section works as well.
>
> I now have a problem, while parsing the standard XML instances (the
> examples are valid against the corresponding XSDs).
You're using the generated resource factory to create the resources used
to process the XML?
> I am always getting a class not found exeption.
From the parser?
> The exception also happens, when I try to parse the generated files
> from the editor example program.
>
> How does the resourceSet get correct initialized to be able to parse
> the XMLs?
Via the plugin.xml registrations.
> Thank you very much for your help!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #897478 is a reply to message #897369] Tue, 24 July 2012 09:07 Go to previous messageGo to next message
Florian B. is currently offline Florian B.Friend
Messages: 21
Registered: July 2012
Location: Hamburg Germany
Junior Member
Ed Merks wrote on Mon, 23 July 2012 15:58
Florian,

Comments below.

On 23/07/2012 6:34 PM, Florian B. wrote:
> Hey,
>
> thx for the advice to create an Ecore Model with xsd files. Smile I was
> able to create a model to parse the the ecore instances, without
> problems.
> On the other hand, i tried to create a New Ecore model from the
> standard XML model I have. It was no problem to create the java code
> and the editor, described in the how to section works as well.
>
> I now have a problem, while parsing the standard XML instances (the
> examples are valid against the corresponding XSDs).
You're using the generated resource factory to create the resources used
to process the XML?
> I am always getting a class not found exeption.
From the parser?
> The exception also happens, when I try to parse the generated files
> from the editor example program.
>
> How does the resourceSet get correct initialized to be able to parse
> the XMLs?
Via the plugin.xml registrations.
> Thank you very much for your help!
>


> I now have a problem, while parsing the standard XML instances (the
> examples are valid against the corresponding XSDs).
You're using the generated resource factory to create the resources used
to process the XML?

I'm not sure... The code above is mainly the main method. I got that code from http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.emf.doc%2Freferences%2Foverview%2FEMF.html

and adopted it to my model.


> I am always getting a class not found exeption.
From the parser?
the exception occures, when i try to demand load the file.

Resource resource = resourceSet.getResource(fileURI, true); (see above)

I really appreciate your help!
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #897491 is a reply to message #897478] Tue, 24 July 2012 09:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Florian,

Try invoking Generate Test Code and look at the generated XyzExample.java.

What file extension is involved in your model? If it's a commonly used
extension like .xml instead of something unique, you'll need to consider
using content types. Keep in mind that the plugin.xml doesn't
regenerate so you'll need to delete it and regenerate it if you
configure your GenPackage to use content types (by specifying a Content
Type Identifier).


On 24/07/2012 11:07 AM, Florian B. wrote:
> Ed Merks wrote on Mon, 23 July 2012 15:58
>> Florian,
>>
>> Comments below.
>>
>> On 23/07/2012 6:34 PM, Florian B. wrote:
>> > Hey,
>> >
>> > thx for the advice to create an Ecore Model with xsd files. :) I
>> was > able to create a model to parse the the ecore instances,
>> without > problems.
>> > On the other hand, i tried to create a New Ecore model from the >
>> standard XML model I have. It was no problem to create the java code
>> > and the editor, described in the how to section works as well.
>> >
>> > I now have a problem, while parsing the standard XML instances (the
>> > examples are valid against the corresponding XSDs).
>> You're using the generated resource factory to create the resources
>> used to process the XML?
>> > I am always getting a class not found exeption.
>> From the parser?
>> > The exception also happens, when I try to parse the generated files
>> > from the editor example program.
>> >
>> > How does the resourceSet get correct initialized to be able to
>> parse > the XMLs?
>> Via the plugin.xml registrations.
>> > Thank you very much for your help!
>> >
>
>
>> I now have a problem, while parsing the standard XML instances (the
>> examples are valid against the corresponding XSDs).
> You're using the generated resource factory to create the resources
> used to process the XML?
>
> I'm not sure... The code above is mainly the main method. I got that
> code from
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.emf.doc%2Freferences%2Foverview%2FEMF.html
>
> and adopted it to my model.
>
>> I am always getting a class not found exeption.
> From the parser? the exception occures, when i try to demand load the
> file.
>
> Resource resource = resourceSet.getResource(fileURI, true); (see above)
>
> I really appreciate your help!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: What is the best way to translate an EMF model instance to a standard XML model instance [message #897549 is a reply to message #897491] Tue, 24 July 2012 13:19 Go to previous message
Florian B. is currently offline Florian B.Friend
Messages: 21
Registered: July 2012
Location: Hamburg Germany
Junior Member
Hi Ed,

thank you very much with the hint to generate test code and to have a look at the example files! Now i'm beginning to understand how to use the generated code. (the test code generation should be mentioned in the documentation as well, since this will really help people i guess ) Smile i really appreciate this.

yes, the file extension is .xml and i changed it .xml in the genmodel. i also changed the content type identifier to the actual type in this case FIBEX.

THX a lot Ed!


Previous Topic:Definition and data editor
Next Topic:EMF Validation on EAttributes
Goto Forum:
  


Current Time: Fri Apr 19 21:29:26 GMT 2024

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

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

Back to the top