[stringtemplate-interest] ST4: XMLModelAdaptor

Terence Parr parrt at cs.usfca.edu
Mon Jan 24 16:27:53 PST 2011


Ok, so this is Crazy cool:

>> <root.("/bookstore/book"): { book | 
>>     <book.title> (<book.title.lang>), <book.author>, <book.year>
>> }>

The only question is: are we somehow entangling the controller in the view? Think about it, xpath is kind of like doing an SQL query, right? On the other hand, you could argue that 

<employee.user.name.last>

is also digging pretty deeply into the model whereas normally we want the controller to pull the data out of the model and push it into the template.

I think that is the conversation we need to have, though I like the idea of some XML integration for marketing reasons. anybody have thoughts?

Ter

On Jan 22, 2011, at 1:21 PM, Collin Fagan wrote:

> Absolutely! I use only the standard XML stuff from the JDK so there are no extra dependencies. I'd be happy to do whatever you need to make this "inclusion ready", unit tests, style standards, whatever, just let me know. 
> 
> Collin
> 
> On Sat, Jan 22, 2011 at 2:52 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> Wow.You are a twisted guy! I like it! :)  I wonder if some built-in XML adapters should be built-in. Should we discuss including in the standard distribution?
> Ter
> On Jan 22, 2011, at 12:01 PM, Collin Fagan wrote:
> 
>> Hi All,
>> 
>> I've been playing with the idea of a model adapter that understands XPath and xml documents. 
>> This is what I ended up with.
>> 
>> Example:
>> 
>> Given an xml file with a structure like this:
>> 
>> <bookstore>
>>     <book>
>>         <title lang="eng">The Adventures of Augie March</title>
>>         <year>1953</year>
>>         <author>Saul Bellow</author>
>>     </book>
>> ...
>> 
>> You can write a template like this:
>> 
>> All Books: <root.("/bookstore/book"): { book | 
>>     <book.title> (<book.title.lang>), <book.author>, <book.year>
>> }>
>> 
>> As you can see the books are being selected with the /bookstore/book XPath expression. ST is able to iterate over everything that is returned and we can access elements and attributes on each selected item via the "." notation. 
>> 
>> Here is the full source code and example for those intersted. 
>> 
>> http://www.box.net/shared/8tnrna4bi7
>> 
>> Enjoy,
>> 
>> Collin
>> 
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 
> 



More information about the stringtemplate-interest mailing list