Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How can I transform an xtext dsl file to xml?
How can I transform an xtext dsl file to xml? [message #1848884] Wed, 22 December 2021 10:10 Go to next message
Soulimane KAMNI is currently offline Soulimane KAMNIFriend
Messages: 20
Registered: February 2020
Junior Member
I have created a grammar using xtext, and generated the DSL. Now, I want to transform the DSL elements (program that is conforming to the grammar) to XML elements. So, I am wondering if there is a framework that allows to do that using Java for example. I could open the files having the extension of the DSL using the eclipse editor "Sample Reflective Ecore Model Editor" and could visualize the elements of the DSL.

I couldn't get the XMI representation of the file.

Is there any solution to perform the transformation?
Thank you in advance.

[Updated on: Wed, 22 December 2021 10:59]

Report message to a moderator

Re: How can I transform an xtext dsl file to xml? [message #1848895 is a reply to message #1848884] Wed, 22 December 2021 14:02 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

In principle, Xtext is just an alternative textual syntax for an EMF resource, so interactively Save as YourFile.xml should work, and I think it used to, but no more. (If Xtext is going to ignore the extension on a regular Save AS, it would be nice if there was a distinct Save AS XML action.)

Programmatically, Xtext loads and parses your model to a Resource conforming to YourDSL.ecore, so programatically after you have loaded/parsed YourDSLResource, you can create a new (XML)Resource, assign the top level YourDSLResource.getContents() to (XML)Resource and save it. If you want to continue using Xext facilities, assign the contents back again.

Regards

Ed Willink
Re: How can I transform an xtext dsl file to xml? [message #1848898 is a reply to message #1848895] Wed, 22 December 2021 14:52 Go to previous messageGo to next message
Soulimane KAMNI is currently offline Soulimane KAMNIFriend
Messages: 20
Registered: February 2020
Junior Member
I still get the same content when I open the file using an XML editor. I need the XML representation so that I can transform the content into another XML content that is compatible with Capella.

[Updated on: Wed, 22 December 2021 14:52]

Report message to a moderator

Re: How can I transform an xtext dsl file to xml? [message #1848903 is a reply to message #1848898] Wed, 22 December 2021 19:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

As I wrote, you must asign the content to an XMLResource so that the XMLResourceFactory or XMIResourceFactory is used to supervise the serialization.

Regards

Ed Willink
Re: How can I transform an xtext dsl file to xml? [message #1848909 is a reply to message #1848903] Thu, 23 December 2021 07:34 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
you can also simply implement MyDslGenerator and produce the final xml there

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XText project migrating from Eclipse to LSP : No ContentAssist working
Next Topic:Xtext 2.26.0.M2 is available
Goto Forum:
  


Current Time: Tue Apr 16 04:31:31 GMT 2024

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

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

Back to the top