How-to generate XML?

Hi,

I have defined a language with editor and everything works fine so far. But I'm completely stuck with the generation part.

If one would like to generate XML from a syntax tree, there are various ways as I understood:

1. using the jetbrains.mps.sampleXml

2. using the jetbrains.mps.xml language which somehow uses jetbrains.mps.gtext for generation

3. maybe also with jetbrains.mps.xmlInternal ?

Now 2. using the xml language seems to be the best and obvious way or not?

Unfortunately this is quasi undocumented and there is no sample or explanation whatsoever for this way. Would it be possible to get a sample/demo or tutorial for generating XML this way at some point in time? I think this would help a lot of MPS-users because MPS is a really cool tool but it is extremely difficult to find out how to do certain things right if one does not generate Java code.

Now for 2., what I see is that one needs to define a XML schema as part of the generator and then try to map the original language onto this schema, or?

Here are the first problems, this xmlSchema language should somehow allow to define a element of type xsd:string but element in a complexType that I define only allows to specify a complexType again, how can I then define a element "description" of type xsd:string?

Second, I did not understand how I then can generate a XML document from a instance of my language then? Somehow I need to use a template or a xmlInternal xmlFile or how is this supposed to work then? Even if I would have a XML AST then, how would I then further generate the text using gtext language etc.???

Please provide some insight and guidance for this problem space!

Thanks, Peter

1 comment
Comment actions Permalink

Peter,

About languages:

1) sampleXml language is just a simple sample to view at, it beter not to be used as a real language

2) xmlInternal language (as it is said in its name) should be used only internally by MPS developers (we have a number of languages called xxxInternal - they also shouldn't be used)

3) xml language is a right choice. You shouldn't care about what language it uses for generation

If you are looking for some samples, you can select the language in logical view (ctrl-alt-shift-L -> type language name -> enter) and press alt-F7. All models using this language will be shown to you - go to any of them and look on its root nodes.

Generation into any language is similar to generation into baseLanguage - there isn't any difference at all, except, maybe, that baseLanguage is imported into generator models automatically, and other languages should be imported manually (via model properties or ctrl-L). Actually, MPS doesn't even know to which language it generates - baseLanguage or some other language.

============================

>one needs to define a XML schema as part of the generator and then try to map the original language onto this schema

Yes, this is exactly what should be done. I'll attach a sequence of screenshot showing how to write such a thing. The feature (attributes) is not very discoverable (I've filed it to our bugtracker: http://youtrack.jetbrains.net/issue/MPS-7356)

> I did not understand how I then can generate a XML document from a instance of my language then?

You should use xmlInternal xmlFile for now; actually it must be moved to xml language (filed: http://youtrack.jetbrains.net/issue/MPS-7357)

> How would I then further generate the text using gtext language etc.???

It will be generated automaticaly. You can think of the process as about reducing more complex languages to simplier languages. If you have reduced your language to a number of simplier ones, it will be generated to text correctly. Actually, it works the following way:  generators are executed one-by-one in the order specified by their priorities. After that only language constructions having textgens should remain. Then textgens generate text files.



Attachment(s):
Screen shot 2010-01-05 at 12.57.36 AM.png
Screen shot 2010-01-05 at 12.57.14 AM.png
Screen shot 2010-01-05 at 12.56.59 AM.png
0

Please sign in to leave a comment.