How can I transform an xtext dsl file to xml? [message #1848884] |
Wed, 22 December 2021 05:10  |
Eclipse User |
|
|
|
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 05:59] by Moderator
|
|
|
Re: How can I transform an xtext dsl file to xml? [message #1848895 is a reply to message #1848884] |
Wed, 22 December 2021 09:02   |
Eclipse User |
|
|
|
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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03192 seconds