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 |
Florian B. 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 |
Ed Merks Messages: 33218 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 #897344 is a reply to message #896148] |
Mon, 23 July 2012 16:34 |
Florian B. Messages: 21 Registered: July 2012 Location: Hamburg Germany |
Junior Member |
|
|
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). 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....
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 #897478 is a reply to message #897369] |
Tue, 24 July 2012 09:07 |
Florian B. Messages: 21 Registered: July 2012 Location: Hamburg Germany |
Junior Member |
|
|
Ed Merks wrote on Mon, 23 July 2012 15:58Florian,
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!
|
|
|
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 |
Ed Merks Messages: 33218 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/
|
|
| |
Goto Forum:
Current Time: Wed Sep 25 07:58:00 GMT 2024
Powered by FUDForum. Page generated in 0.07552 seconds
|