XML output from MySQL
        Posted  
        
            by NumberFour
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by NumberFour
        
        
        
        Published on 2010-05-17T08:46:34Z
        Indexed on 
            2010/05/17
            8:50 UTC
        
        
        Read the original article
        Hit count: 499
        
Hi,
is there any chance of getting the output from a MySQL query directly to XML?
Im referring to something like MSSQL has with SQL-XML plugin, for example:
SELECT * FROM table WHERE 1 FOR XML AUTO
returns text (or xml data type in MSSQL to be precise) which contains an XML markup structure generated according to the columns in the table.
With SQL-XML there is also an option of explicitly defining the output XML structure like this:
SELECT
  1       AS tag,
  NULL    AS parent,
  emp_id  AS [employee!1!emp_id],
  cust_id    AS [customer!2!cust_id],
  region    AS [customer!2!region]
 FROM table
 FOR XML EXPLICIT
which generates an XML code as follows:
<employee emp_id='129'>
   <customer cust_id='107' region='Eastern'/>
</employee>
Do you have any clues how to achieve this in MySQL?
Thanks in advance for your answers.
© Stack Overflow or respective owner