Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » XSD To ECore to XML(Genrating XML file from XSD by using ECore)
XSD To ECore to XML [message #634650] Fri, 22 October 2010 15:20 Go to next message
Jean Duracel is currently offline Jean DuracelFriend
Messages: 10
Registered: October 2010
Junior Member
Dear reader,

I'm trying to generate an XML File from it's XSD by using it's associated ecore file but without generating the pojos.

I started by loading the ecore file and then by using ModelDataGenerator I produced my List<EObject>.

Then I wanted to convert this list by using :

EMFModelConverter emfModelConverter = new EMFModelConverter();
List<Object> lo = emfModelConverter.convert(leo);

In order to have the possibility to convert my list of Object by using an ModelXMLSaver.

The trouble is that since I haven't generated the pojos associated to my model there is no ModelPackage registered and then I get an error on the EMFModelConvertion.

Please can you help or give me some advice ... Is there some other way to get a generated XML file from its XSD ? Is it possible to get a dynamic PackageModel in order to register it and having the emfModelConvertion working ...

Thanks in advance for you comments.

[Updated on: Fri, 22 October 2010 15:37]

Report message to a moderator

Re: XSD To ECore to XML [message #634658 is a reply to message #634650] Fri, 22 October 2010 15:45 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jean,
Instead of converting to Texo objects you can also directly store the EObjects in a xml file, try something like this:
Resource res = new XMLResourceImpl(URI.createFileURI("/tmp/test.xml");
res.getContents().addAll(eObjects);
res.save(optionsHashMap);

gr. Martin

On 10/22/2010 05:20 PM, Jean Duracel wrote:
> Dear reader,
>
> I'm trying to generate an XML File from it's XSD by using it's
> associated ecore file but wihtout generating the pojos.
>
> I started by loading the ecore file and then by using ModelDataGenerator
> I produced my List<EObject>.
>
> Then I wanted to convert this list by using :
>
> EMFModelConverter emfModelConverter = new EMFModelConverter();
> List<Object> lo = emfModelConverter.convert(leo);
>
> In order to have the possibility to convert my list of Object by using
> an ModelXMLSaver.
>
> The trouble is that since I haven't generated the pojos associated to my
> model there is no ModelPackage registered and then I get an error on the
> EMFModelConvertion.
>
> Please can you help or give me some advice ... Is there some other way
> to get a generated XML file from its XSD ? Is it possible to get a
> dynamic PackageModel in order to register it and having the
> emfModelConvertion working ...
>
> Thanks in advance for you comments.
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: XSD To ECore to XML [message #634667 is a reply to message #634658] Fri, 22 October 2010 16:13 Go to previous messageGo to next message
Jean Duracel is currently offline Jean DuracelFriend
Messages: 10
Registered: October 2010
Junior Member
Hi Martin,

I did that but the result is a little disapointing :

The XSD file was :
<xsd:element name="OrderCancelled" type="OrderCancelled"/>
<xsd:complexType name="OrderCancelled">
<xsd:sequence>
<xsd:element name="justification" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

And I obtain this :
<?xml version="1.0" encoding="ASCII"?>
<OrderCancelled:DocumentRoot xmlns:OrderCancelled=" file:///C:/apps/java/eclipse/bdd_workspace/EcoreXSD/xsd/Orde rCancelled.xsd">
<orderCancelled justification="String16"/>
String1</OrderCancelled:DocumentRoot>

The ecore file contains :

<eClassifiers xsi:type="ecore:EClass" name="OrderCancelled">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="OrderCancelled"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="justification" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="justification"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>

Wy is the justification seen as an attribute ? Why did I get a string1 contain ?
Is it due to the fact that I don't use the texo conversion ?

Any idea ?

Thanks in advance.

Jean
Re: XSD To ECore to XML [message #634700 is a reply to message #634667] Fri, 22 October 2010 18:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Jean,

Use the generated resource factory to create the resource (or configure
it the way the factory does).


Jean Duracel wrote:
> Hi Martin,
>
> I did that but the result is a little disapointing :
>
> The XSD file was :
> <xsd:element name="OrderCancelled" type="OrderCancelled"/>
> <xsd:complexType name="OrderCancelled">
> <xsd:sequence>
> <xsd:element name="justification" type="xsd:string" minOccurs="1"
> maxOccurs="1"/>
> </xsd:sequence>
> </xsd:complexType>
>
> And I obtain this :
> <?xml version="1.0" encoding="ASCII"?>
> <OrderCancelled:DocumentRoot
> xmlns:OrderCancelled=" file:///C:/apps/java/eclipse/bdd_workspace/EcoreXSD/xsd/Orde rCancelled.xsd">
>
> <orderCancelled justification="String16"/>
> String1</OrderCancelled:DocumentRoot>
>
> The ecore file contains :
>
> <eClassifiers xsi:type="ecore:EClass" name="OrderCancelled">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="OrderCancelled"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="justification" lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//String">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="justification"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
>
> Wy is the justification seen as an attribute ? Why did I get a string1
> contain ?
> Is it due to the fact that I don't use the texo conversion ?
>
> Any idea ?
>
> Thanks in advance.
>
> Jean
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XSD To ECore to XML [message #634777 is a reply to message #634700] Sat, 23 October 2010 12:30 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jean,
My initial answer was too short, as Ed says it is better to use the XMLResourceFactoryImpl to create a XML resource.

Resource res = new XMLResourceFactoryImpl().createResource(URI.createFileURI("/tmp/my.xml "));

gr. Martin
Previous Topic:how to load an XML-Instance into Ecore and access its attribute values
Next Topic:Multiple tabs inside an editor
Goto Forum:
  


Current Time: Fri Apr 19 12:58:11 GMT 2024

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

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

Back to the top