Best practice: reading from xml and transforming data into MPS language

Hey forum!

I'd like to know what's the best approach for my issue.
Note: I only need to filter out tags which match one name and it's subtags of my xml.
Should I use the OpenAPI and/or are there some useful plugins, which I could use?
Thanks in advance!

Regards
msch95
9 comments
Thanks, Vaclav. I don't think that custom persistence fits my needs.
I'd like to elaborate again..
I have an xml like this:
<persons>
  <person name"Chuck">
    <car name="Ford"/>  
  </person>
  <person name="Chuck"/>
</persons>
prettyPrint();

So my plan is to filter all car tags and it's childs (perhaps with java) and to transform that into my MPS language. I don't want to save my MPS language in xml format. I only plan to import the data into my language and nothing else. (so that I don't have to input it myself via keyboard, because the xml has 15000 lines)
0
I see. In that case, indeed, you have to leverage the Open API to gain programatic access to your models.

Vaclav
0
Do I need to iterate over the xml file manually and construct my MPS nodes<> manually or is there something which works like a mapper and is therefore easier?
I thought of something like this:
Car:node<Car>
  name:node<Car>.name = "data from xml"

Regards
0
In one project we did something similar. Best practice was to divide the task into two steps:
1) import the XML text file as an MPS XML model (could be done via custom persistence as Vaclav mentioned)
2) do a Model2Model transformation from this MPS XML model into the target model using the Scripts Aspect
We did this because the XML file was given and did not change, but the language for the target model was under construction and so we separated what changed from what was invariant (SRP known from OOP also works for language engineering).
And yes, this includes constructing the MPS nodes<> manually. Maybe your mapping is easy enough so that a generic mapping could work - defined in your custom mapping language. Would be interesting for me to see if that worked for you.
0
Thanks for your reply, Jens.
The xml model is unfortunately not easy. Now I see, what Vaclav pointed me to. Yes my xsd for my xml won't change. I posted a question about xsd in another thread. So far I've achieved to build a plugin, read my xml via Java and transform the data into my MPS language. I can follow your approach Jens, but I can't see any advantage of using Custom Persistence and the script aspect over my approach. Maybe you have time to elaborate if I'm wrong.
Thank you!
0

Hi,

 

Kindly let me know the means how i can read a XML document using SAX Parser within MPS and also load the values into the sModel.

 

Regds
Rahul.

0

Hi,

Kindly let me know the means how i can read a XML document using SAX Parser within MPS and also load the values into the sModel.

Regds

Rahul.

0

Read your xml data using a Java SAX or DOM Parser and create your MPS nodes accordingly. For instance:

node<myconcept> n = new node<myconcept>;n.prop = "Hello world";

Regards

msch95

0

Please sign in to leave a comment.