如何将数据表转换为xml格式 [英] How to convert the datatable to xml format

查看:70
本文介绍了如何将数据表转换为xml格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将输出文件作为xml格式,如下所示



i want to get the output file as xml format like below

<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来自eventid,日期,时间,持续时间,名称,sysnopsis,logline,我的数据表中的主题



i使用xmlwrite来传递它..但输出不是以上格式..

任何plz帮助




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

推荐答案

嗯......你可以使用DataTable.WriteXml [ ^ ]方法...
Well...you could use the DataTable.WriteXml[^] method...


我已经为数据集做了这个。你可以尝试使用DataTable

I have done this for dataset.You can try it for DataTable
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应包含xml


tSerilaizedObject should contain the xml


如何使用ASP.NET和C#从/向csv / XML / excel导入/导出数据库数据。
http://dotnetawesome.blogspot.com/2013/11/how-to-import-export-database-data-from_16.html





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();
                }
            }
        }


这篇关于如何将数据表转换为xml格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆