XML from SQL result

Marcin Stępnicki mstepnicki at gmail.com
Wed Jun 27 03:25:16 EDT 2007


Hello.

I've skimmed through many Python&XML related books/articles but I am
unable to find anything that is similar to my problem - but it seems to
me that it should be common.

Anyway: I've got the SQL query which returns:

col1 | col2 | col3
-----+------+-----
  a  | a10  | b20
  a  | a10  | b30
  a  | a20  | b30

I need to generate the following:

<tag1 "col1"="a">
	<tag2 "col2"="a10">
		<tag3 "col3"="b20" />
		<tag3 "col3"="b30" />
	</tag2>

	<tag2 "col2"="a20">
		<tag3 "col3"="b30" />
	</tag2>
</tag1>  

Using Elementree it's not a problem when returned data is "flat", not
hierarchical. However, that's not the case.

Questions:

1) (I'll ask that on PostgreSQL group too) I use PostgreSQL. I understand
that in order to achieve what I want directly from RDBMS I need SQL/XML
language support which will be included in 8.3 which is not yet available.

2) Provided that I can't generate it from 1) should I take a deeper look
into Gnosis Utils? http://www.gnosis.cx/download/Gnosis_Utils.More/ ? 

3) I can generate series of select queries based on previous queries, but
I can't imagine there isn't a better solution.

Could you please clarify these for me? I'm a bit puzzled and frankly
don't know where to start. Even a single URL which explains it in detail is
greatly anticipated :).

Thank you for your time,
Marcin

-- 
| And Do What You Will be the challenge | http://apcoln.linuxpl.org
|    So be it in love that harms none   | http://biznes.linux.pl
|   For this is the only commandment.   | http://www.juanperon.info
`---*  JID: Aragorn_Vime at jabber.org *---' http://www.naszedzieci.org



More information about the Python-list mailing list