[Tutor] MySQL -->Python-->XML for JSviz
Kent Johnson
kent37 at tds.net
Tue Jul 3 23:50:31 CEST 2007
Picio wrote:
> Hello all, I need some advice to choose an xml generator for jsviz a
> tool in javascript to create some wonderful graphs (SnowFlake or Force
> directed).
>
> Starting from a SQL table (mysql) I need to create a XML file with a
> structure like this:
> <node root....>
> <node id... text... ></node>
> <node id... text... ></node>
> <node id... text... ></node>
> <node id... text... ></node>
> <node id... text... ></node>
> <node id... text... ></node>
> </node>
>
> Where nodes attributes are the MySQL table fields (the PK will be the
> attribute).
> I know there are a lot of good tools to do this in pyhton (some maybe
> is already shipped with pyton itself), but since I need a lot of
> flexibility for the future I'd like to use an Object relational mapper
> like SQLAlchemy or SQLObject todo the job. When I say flexibility, I
> have in mind a solution to have multiple formats coming outside of the
> ORM:
> json, csv, plain text etc...
I'm not sure why you need an ORM here. ISTM you just need a database
connection, the name of a table containing the data and a list of the
fields you want to pull out of it. Then a simple SELECT gets you the
data in a list of lists; pass the same list of field names and the list
of data to whatever output formatter you want. I think the whole program
would only be 20-30 lines of code.
ElementTree is a good XML package, it is part of Python 2.5 and
available as an add-on for older Python versions.
Kent
More information about the Tutor
mailing list