[stringtemplate-interest] ST4: XMLModelAdaptor

Collin Fagan collin.fagan at gmail.com
Sat Jan 22 12:01:18 PST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110122/6d240a9f/attachment.html 


More information about the stringtemplate-interest mailing list