SQL recordset -> XML

Richard Shea richardshea at fastmail.fm
Mon Oct 27 18:00:24 EST 2003


Hi - Not sure if this is a really stupid question or not ... so I
thought I'd ask it anyway ;-)

I want to take data from a SQL generated recordset and represent it as
XML.

I can think of *very* straightforward ways (as I'm sure all you can)
to do that (please excuse rough/weird pseudo code) ...

if you had a recordset resulting from a query something like :

select 
Suburb_Value,City_Value 
from 
Table_Locations 
ORDER BY CITY_VALUE,SUBURB_VALUE

... and you then did something like this (only a lot tidier) ...

do while no_more_records
    if Suburb_Value <> CurrentSuburb
        output Closing_City_Tag
        output Opening_City_Tag(City_Value)
    end if
    output Opening_Suburb_Tag
    output Suburb_Value
    output Closing_Suburb_Tag
end do

... you'd get what I'm after but it's all a bit clunky and of course
very specific the current recordset.

I just wondered if anyone had written anything to at least help this
process a bit ?

I'm in the process of reading the O'Reilly "XML and Python" book and
there's any amount of support for 'input XML' but nothing really to
assist with output.

Is there a smart way to do this ?

thanks

richard shea.




More information about the Python-list mailing list