Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to get the output file as xml format like below

XML
<EVENT_SECTION>
    <EVENTID>47920140220E1</EVENTID>
    <START>
      <DATE>2014/02/20</DATE>
      <TIME>00:00:00</TIME>
    </START>
    <EPG_SECTION>
      <DURATION>00:30:00</DURATION>
      <EPG Language="Eng">
        <NAME>Comedy Express</NAME>
        <SYNOPSIS>The program features a compilation of comic scenes from popular films.</SYNOPSIS>
        <LOG_LINE>Comedy Express</LOG_LINE>
      </EPG>
      <THEME>1</THEME>
      <RATING Country="IND">0</RATING>
    </EPG_SECTION>



i have from eventid,date, time, duration,name, sysnopsis , logline,theme in my datatable

i using xmlwrite to convet it.. but the output is not in the above format..
any plz help
Posted
Updated 23-Feb-14 23:19pm
v2
Comments
Kornfeld Eliyahu Peter 24-Feb-14 5:22am    
Your data comes form SQL (MS) server?
Try use this - http://technet.microsoft.com/en-us/library/ms178107.aspx

Well...you could use the DataTable.WriteXml[^] method...
 
Share this answer
 
I have done this for dataset.You can try it for DataTable
C#
XmlSerializer tXmlSerializer = new XmlSerializer(tDataSet.GetType());
System.IO.MemoryStream tStream = new System.IO.MemoryStream();
tDataSet.DataSetName = "ITEM";
tDataSet.Tables[0].TableName = "MST_ITEM";
tDataSet.WriteXml(tStream);
String tSerilaizedObject = System.Text.Encoding.UTF8.GetString(tStream.ToArray());

tSerilaizedObject should contain the xml
 
Share this answer
 
v2
How to import /export database data from /to csv/XML/excel using ASP.NET and C#.

for complate example visit: http://dotnetawesome.blogspot.com/2013/11/how-to-import-export-database-data-from_16.html


protected void btnExport_Click(object sender, EventArgs e)
        {
            using (MuDatabaseEntities dc = new MuDatabaseEntities())
            {
                List<EmployeeMaster> emList = dc.EmployeeMasters.ToList();
                if (emList.Count > 0)
                {
                    var xEle = new XElement("Employees",
                        from emp in emList
                        select new XElement("Employee",
                            new XElement("EmployeeID", emp.EmployeeID),
                            new XElement("CompanyName", emp.CompanyName),
                            new XElement("ContactName", emp.ContactName),
                            new XElement("ContactTitle", emp.ContactTitle),
                            new XElement("EmployeeAddress", emp.EmployeeAddress),
                            new XElement("PostalCode", emp.PostalCode)
                            ));
                    HttpContext context = HttpContext.Current;
                    context.Response.Write(xEle);
                    context.Response.ContentType = "application/xml";
                    context.Response.AppendHeader("Content-Disposition", "attachment; filename=EmployeeData.xml");
                    context.Response.End();
                }
            }
        }
 
Share this answer
 
CODE FOR YOUR SOLUTION



DataTable dtdt = (DataTable)Grid_Name.DataSource;

//or

//(data table came from database)



dtdt.TableName = "MySampleTable";


MemoryStream mstr = new MemoryStream();
dt.WriteXml(mstr, true);
mstr.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(mstr);
string xmlString;
xmlString = sr.ReadToEnd();
return (xmlString);
 
Share this answer
 

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