[stringtemplate-interest] Re : ST4: XMLModelAdaptor

Terence Parr parrt at cs.usfca.edu
Tue Jan 25 11:50:34 PST 2011


On Jan 24, 2011, at 7:46 PM, Matthieu Wipliez wrote:

> Personally I love the idea of being able to produce textual code from XML with 
> StringTemplate, which is a lot easier to do than with, say, XSLT :-)
> I think that the idea of using XPath as properties of the model is nice and 
> feels pretty natural.

It definitely sounds convenient, but it sure makes me nervous! imagine

<db.("SELECT * FROM USERS NATURAL JOIN EMPLOYEE"):employeeInfo()>

That is also very convenient but the problem is that, while not causing side effects, it does tie the template to the model. In other words, when the database schema changes, all of the templates break. that's usually a good test to see if there's a violation of separation.

Now with

<root.("/bookstore/book"):book()>

we have a similar situation right? Once the structure of the XML changes, the templates break. Contrast this with

<books:book()>

where there is absolutely no tying to the model whatsoever.

> Also, this respects the push strategy IMO, since the XML model is computed 
> beforehand. This may even be safer than using POJO-based model, because with 
> your own model you are free to modify the model in methods, which is not the 
> case with XPath expressions (they do not modify the underlying XML model).

It definitely pushes data in there and has no side effects, but it still ties the template to the model tightly. If our member correctly, I even considered a simple type reliance to be an entanglement. Naturally, we actually have work to do, and so I needed to allow

<user.name>

and things like that where obviously you need to know what the type of user is.

Perhaps, we can put the XML adapter as a contribution on the wiki rather than officially blessing the approach in the distribution itself?

Ter


More information about the stringtemplate-interest mailing list