Mysql – Get data from table as XML or HTML

If you are trying to get all the data from mysql table as an xml


Consider u have a table says employees which has an approx of 2000 employee details in it and you are developing a mobile application to show the list in that which would use xml parsing to get data from server.

So, if you are developer in server side then what you do to get all of them as an xml ?

Conventionally any programmer will use a for or while loop to get this done and lays the xml data layout. in more details as follows

  1. select * from employees is executed to get all data.
  2. start the xml header
  3. A loop is runned all over 2000 records and render each record as an xml node.
  4. end the xml.

This becomes a big burden for the server or processor

To serve such purpose mysql provides u a fine method combination concat and group_concat

SET @xml:='';
SELECT @xml:=concat(@builtxml,"",emp.number,"",,"") "XML" FROM employees emp,(SELECT @builtxml:='') a ORDER BY @builtxml DESC LIMIT 0,1
Thanks for reading - your comments encourage me, Rama Krishna Chunduri