generate xml out of dsl

Hello forum members!

I wonna know how if it's possible to generate a XML tree out of my defined DSL as it's stated here:
https://www.jetbrains.com/mps/concepts/

Currently, MPS is particularly good for, but is not limited to, generating Java code. You can also generate XML, HTML, JavaScript, and more.


On the manual page I was able to find examples only with Java. If you could provide some examples or links, it would help me a lot.

Thanks in advance!
8 comments
Hi mschalk,

I recommend the language jetbrains.mps.core.xml as target language for your generator. Just add this language to your generator model ("Used Languages") and its structure aspect to "Dependencies". Afterwards you are able to map your DSL elements to XML elements.

Sorry, I was not able to find any example for that but it is not that complicated, since it is the same like with Java but you create a XMLFile node instead and fill in XML code lines.
If you get stuck somewhere, I can probably help you.

Regards,
LaAck
0
Hi LaAck!
Thanks for your reply.
I'll try that later on, and if I have some more questions, I'll come back to you.

Regards,
mschalk
0
Hi again LaAck!

Do you use the sampleXML project, which is included in the MPS Jetbrains examples?
If yes, how do you use it?
I want my xml file generation generic, which means for instance if I add a new property I don't want to change my code in the textGen folder. Can you give me advice?

Kind regards,
mschalk
0
Hi mschalk! ;)

No, I use the built-in MPS language jetbrains.mps.core.xml. Add this language to the dependencies of the generator aspect ("Used Languages") as well as the xml "structure" aspect (jetbrains.mps.core.xml.structure) to the generator model's dependencies. Finally add the language to the "Used Languages" of the generator model (called main@generator by default). Now you are able to use the xml language in the generator aspect.

To my current understanding of what you are currently trying to do, you don't need to touch the textGen folder. The reason is that the built-in XML language has its own generator for transforming a jetbrains.mps.core.xml DSL snippet to XML text. What you have to do is to provide the transformation from your DSL language to the jetbrains.mps.core.xml DSL snippet. This is done in the generator aspect as shown in the Calculator tutorial.
What do you mean by "if I add a new property"? Does it mean that you want to add a new property to the language specification or to the artifacts, written in your DSL? The former is difficult to implement generically, the latter, in contrast, very easy.

Regards,
LaAck
0
Thanks so much for your patience and support, LaAck!
You let me into the right direction!
0
another question:
How can I add an attribute to my xml node? ENTER or ALT+ENTER doesn't work.

Code
<asdf>  
    </asdf>
prettyPrint();

So I added a macro and returned the attributes in a string. Is there an easier solution?

Code
<$asdf>  
    </asdf>
prettyPrint();
0
You're welcome. I also got help when I started with MPS. :)

Regarding your latest question, just press SPACE after your XML tag name and afterwards the name or placeholder for your attribute and an '=' symbol. This should work. To fill in all attributes based on the DSL properties you mentioned, just put a LOOP node macro around the whole attribute and afterwards property macros for both the name and the value. Alternatively you can put a COPY_SRCL around your attribute and add another reduction rule to your mapping config transforming each DSL property into a node of concept XmlAttribute. No matter which way you choose, you have to iterate over the properties as I wrote in your related post.

Regards,
LaAck
0
Thanks. That helped a lot. Issue closed.

0

Please sign in to leave a comment.