Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get XML representation of SQL server database ?
for example user will type www.blablabla.com?name=joe
and the result is XML based on the database. example:

<USER>
<ADDRESS>aaa</ADDRESS>
<PHONE>7873875</PHONE>
<AGE>67</AGE>
</USER>


I dont want the results to show in xml GUI like control, I want it pure XML like this

<USER>
<ADDRESS>aaa</ADDRESS>
<PHONE>7873875</PHONE>
<AGE>67</AGE>
</USER>


thanks in adanced
Posted

 
Share this answer
 
You can use XQuery for xml operation,

Check the url,
http://www.simple-talk.com/sql/learn-sql-server/the-xml-methods-in-sql-server/[^]

cheers
 
Share this answer
 
You can use XmlSerialization.

StringWriter strWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);

xmlWriter.WriteStartElement("RootNode"); 
// instead of RootNode, you can have the required table name in it.

SqlConnection mySqlConnection;
mySqlConnection = new SqlConnection(sConnection);
mySqlConnection.Open();

XmlReader xmlReader = new SqlCommand("Select * From Table1 FOR XML AUTO, Elements", mySqlConnection).ExecuteXmlReader();
xmlWriter.WriteNode(xmlReader, true);

xmlReader.Close();
xmlWriter.WriteEndElement(); 

mySqlConnection.Close();


You will have the xml string in strWriter. You can use XmlSerializer class.

OR,

You can get help from the below link
http://blogs.msdn.com/b/saurabh_singh/archive/2010/05/11/export-sql-table-records-to-xml-form.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900