[stringtemplate-interest] Re : ST4: XMLModelAdaptor
Terence Parr
parrt at cs.usfca.edu
Tue Jan 25 11:53:40 PST 2011
On Jan 24, 2011, at 8:12 PM, Collin Fagan wrote:
> they do not modify the underlying XML model
>
> Yes and that is why I think xpath is much closer to a property invocation chain then a SQL query. In the end you can only do so much with xpath. So what can you do?
> • Walk the document
> • Access elements and attributes
> • querying/filtering based on the content of elements and attributes
> • Simple math.
> The filtering and math, while admittedly the responsibility of the controller in an MVC architecture, is rather benign in my opinion.
I've moved away from doing any kind of model walking in my templates. I used to do some recursive template invocations to walk trees. What I decided was that that really should be part of the controller or the model. While ST can do it, I don't think it's the most effective approach and, of course, starts to entangle your template to the type and structure of your model. so, now I walk the tree or graph or whatever in the model controller parts and push simpler data into the template. so, when I want to print out a DFA, I create simple node and edge templates then create a bunch of them while I walk the DFA. printing out the DFA is than simply a matter of:
<nodes>
<edges>
> Let's compare this to a something truly horrific. I guarantee the following compiles and executes but I shall never release the code behind it for fear it might spread like a contagion.
>
> main(groovy) ::= <<
>
> A groovy string: <groovy.(" 'hi!' ")>
>
> Lets do Math! 5 + 7 = <groovy.(" 5 + 7 ")>
>
> Lists: <groovy.("[5, 6, 7, 8]"); separator=" and ">
>
[yikes!]
twisted and clever. I'll pretend I never saw this ;)
I guess this is the point; I don't want people starting to abuse this adapter thing. all they have to do is create an adapter for a database object and pass whatever strings they want. perhaps we shouldn't encourage this cleverness :)
Ter
More information about the stringtemplate-interest
mailing list