Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an XML file from MySQL Data queries?

Tags:

mysql

xml

I would like to know a way to create an XML file using MySQL queries only. without using any scripting language at all.

Are there any books, tutorials on this topic ?

UPDATE:

I would like to clear it out that I want to use sql queries which would forward XML data to a php Script.

like image 490
Ibn Saeed Avatar asked Oct 18 '25 23:10

Ibn Saeed


2 Answers

Here's a blog post about returning XML from MySQL SELECT queries:

xml_escape(value) - 
  replace characters not allowed in xml with the escape sequences

xml_attr(name, value) - 
  create an xml attribute 

xml_tag(tagname, tagvalue, attrs, subtags) -
  create a tag 

And here's a post about writing the results of a MySQL query to a file:

SELECT whatever FROM whereever
INTO OUTFILE '/path/to/file.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

Combining these two techniques should let you create an XML file without any scripting.

like image 175
Welbog Avatar answered Oct 21 '25 15:10

Welbog


You can do it quite easily from the command prompt, see this:

http://blog.reindel.com/2007/09/27/output-mysql-query-results-to-xml-from-the-command-prompt/

like image 31
karim79 Avatar answered Oct 21 '25 16:10

karim79