Recursive XML Generation

Hi,

I have in my language a group concept and a leaf concept that can appear in the XML output of my generator in multiple positions.

Of course I would like to only once define a model for the XML generator output and reuse it.

So I have a root concept (service) and a XML schema and xmlInternal file model in the generator

mps_generator.tiff

service.xml is the xmlInternal file model for the root node, request.xml and requestgroup.xml are the xmlInternal file models for the group or leaf concept (request) correspondingly

I want e.g. in the XML afterwards

<service>

  <requestgroup>

    <requestgroup ...>

      <request .../>

    </requestgroup>

    <request .../>

    <request .../>

  </requestgroup>

  <request .../>

  <request .../>

  ...
</service>
So a requestgroup or request can appear in a service or another reuqest group.
My mapping looks like this at the moment:
mps_mappingconfig.tiff
and I get the <service> XML generated but empty
I try to use $MAP_SRCL$ macro inside the body of the service tag:
mps_generator_model.tiff
but I suppose I'm missing a mapping configuration for Request and RequestGroup. The question now is, it cannot be a root maping rule because Service is the only root concept.
I would have guessed a weaving rule as this would allow to insert the mapped output nodes of request and requestgroup to be inserted into the parent root service node.
But a weaving rule takes a "external template ref" and referencing the request.xml or requestgroup.xml generator models does not seem to be a valid option.
How can i do this?
Thanks, Peter


Attachment(s):
mps_generator.tiff
mps_mappingconfig.tiff
mps_generator_model.tiff
5 comments
Comment actions Permalink

Please please help!

weaving rules seem maybe util, but what should I do with a template, when I have a model (xmlInternal file) that defines what to generate?

request.xml in above picture is a model not a template and it specifies how a concept Request should be made into a XML document.

But how can say that all children of Service which are a Request should be generated by this model and all concept children of type RequestGroup with the model requestgroup.xml?? How?

I tried all kinds of rules and functions and in the mapping config but I don't understand it, the documentation of $MAP_SRCL$ is not understandable.

Please please help,

Thanks, Peter

0
Comment actions Permalink

Hi Peter,

what you need in that case are two reduction-rules. One that reduces YOUR request-nodes and requestgroup-nodes to according XML-Elements.

Then define a root-mapping-rule that takes your service-node and mapps to your xml-doc-template which in turn calls the $COPY_SRCL$-Macro on the child-elements within your service-element.

While performing the $COPY_SRCL$-Macro MPS copies the nodes and tries to reduce nodes as long as there is something to reduce (Generator-Micro-Steps).

Viola! You should come out with your desired XML-doc.

Regards,

Mirko

0
Comment actions Permalink

> what you need in that case are two reduction-rules. One that reduces YOUR request-nodes and requestgroup-nodes to according XML-Elements.

A reduction rule has as a consequence the options

reduction_rule.tiff

I do have a template for Request that I would like to produce from a concept of type Request which is

request_templ.tiff

But I have no way to specify this template in the above position, I could make a inline template and choose XmlFile and paste the content of a existing "root" template in there. Is it a problem that I have created it as a root template or how can I reference this template then?

Then I had a Service Template like so:

service_template.tiff

And a rule mapping such as this

mapping_rules.tiff

Just how do I refer so the exising template with the (N) symbol in this place???

Thanks, Peter



Attachment(s):
reduction_rule.tiff
request_templ.tiff
service_template.tiff
mapping_rules.tiff
0
Comment actions Permalink

while I kept experimenting, I create a inline-template in the place of the reduction rule consequence (red in the picture above) and tried pressing Option-Return like for inserting a node macro e.g.

There I found a menu item "Convert to template reference" what I did. The effect is that a new template reference is create, called template1 (where one cannot change the name as it seems) that when one double clicks exactly the request.xml or requestgroup.xml XmlFile templates get opened.

template_ref.tiff

This somehow looks promising, but generate text on my sandbox model still does not generate anything.

I just would like to understand, what this is really what I did. I did just create an empty inline-template and converted it to a reference to the right template, hm. Could I have typed like request.xml and converted that, or?



Attachment(s):
template_ref.tiff
0
Comment actions Permalink

Hi Peter,

sorry for that late reply, but i was on a looong vacation ;-) ...

what i can say is that you do not only have the consequences you show in your reduction_rule.tiff. You can execute any template-file as concequence of reduction-rule (just create on and reference it -> it should be listed in code-completion-menu OR type any string and create the template via Intention -> per keystroke <Alt-Return>). So a COPY-MACRO plus reduction-rule for the recursion-parts one by one will do the job.

Assuming you understand german :-): before vacation i wrote an article for the actual Java-Magazin 06/2010 and on vacation an online-tutorial at my homepage (not yet completely finished (95% done) but hopefully soon). The online-thing will be more interesting to you i think...

English version will follow soon.

Hope that helps a bit.

Mirko

0

Please sign in to leave a comment.