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
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
Please sign in to leave a comment.
https://confluence.jetbrains.com/display/MPSD32/Custom+Persistence+Cookbook
Vaclav
I'd like to elaborate again..
I have an xml like this:
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)
Vaclav
I thought of something like this:
Car:node<Car>
name:node<Car>.name = "data from xml"
Regards
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.
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!
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.
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.
Read your xml data using a Java SAX or DOM Parser and create your MPS nodes accordingly. For instance:
Regards
msch95