Fetch and render fetched values from MySQL tables as XML

Australia

New Member
I am fetching results out of a query from a table:\[code\]def getdata() self.cursor.execute("....") fetchall = self.cursor.fetchall() result ={} for row in fetchall: detail1 = row['mysite'] details2 = row['url'] result[detail1] = row return result\[/code\]Now I need to process the result set as generated :\[code\]def genXML() data = http://stackoverflow.com/questions/10480355/getdata() doc = Document()""create XML tree structure"""\[/code\]Such that data would hold all the rows as fetched from query and I can extract each column values from it? Somehow I am not getting the desired out. My requirement is to fetch result set via a DB query and store result into a placeholder such that I can easily access it later in other method or locations?================================================================================I tried the below technique but still in method 'getXML()' I am unable to get each dict row so that I can traverse and manipulate:\[code\] fetchall = self.cursor.fetchall() results= [] result={} for row in fetchall: result['mysite'] = row['mysite'] result['mystart'] = row['mystart'] .................................. results.append(result) return resultsdef getXML(self): doc = Document() charts = doc.createElement("charts") doc.appendChild(charts) chartData = http://stackoverflow.com/questions/10480355/self.grabChartData() for site in chartData: print site[??]\[/code\]So how do I get each chartData row values and then I can loop for each?Note: I found that only last row fetched values are getting printed as in chartData. Say I know that 2 rows are getting returned by the query. Hence in case I print the list in getXML() method like below both rows are same:\[code\]chartData[0]chartData[1]\[/code\]How can I uniquely add each result to the list?
 
Back
Top