Getting data from MySQL in XML

by Rekha 2009-12-10 12:34:21

The following code is used to get the mysql output in XML format,

>mysql -u login_name -p password -X -e "select * from table_name" database_name


Sample Result:


<?xml version="1.0"?>
<resultset statement="select * from test">
<row>
<id>1</id>
<name>me</name>
<age>88</age>
</row>

<row>
<id>2</id>
<name>you</name>
<age>10</age>
</row>

<row>
<id>3</id>
<name>she</name>
<age>25</age>
</row>
</resultset>


You can also get the output in html format using -H option

>mysql -u login_name -p password -H -e "select * from table_name" database_name


Sample Output:


<table BORDER=1><tr><th>id</th><th>name</th><th>age</th></tr><tr><td>1</td><td>m
e</td><td>88</td></tr><tr><td>2</td><td>you</td><td>10</td></tr><tr><td>3</td><t D>she<td>25</td></t></tr></table>

Tagged in:

1152
like
0
dislike
0
mail
flag

You must LOGIN to add comments