Some of the information here may be outdated, please check the book instead

Now that it is needed since web2py exports already in CSV but you can do define

def export_xml(rows):
    colnames=[item.replace('.','_') for item in rows.colnames]
    for row in rows.response: records.append(TAG['record'](*[TAG[colnames[i]](row[i]) for i in idx]))
    return str(TAG['records'](*records))

Now if you have a model like

for i in range(100): db.mytable.insert(myfield=i)

you can get your data in XML by doing

print export_xml(db().select(db.mytable.ALL))

Notice that'a','b',c='d')



both generate the following XML

<name c="d">ab</name>

where 'a' and 'b' and 'd' are escaped as appropriate. Using TAG you can can generate any HTML/XML tag you need and is not already provided in the API. TAGs can be nested and are serialized with str()

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.