我在sql表中有数据,数据将在标签内转换为xml格式 [英] I have data in sql table that data will be convert in to xml format inside tag
本文介绍了我在sql表中有数据,数据将在标签内转换为xml格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在该表中有数据表有数据将数据转换成xml格式,如
里面标签
示例
< CPSMSStateSchemeMapping >
< StateCode > 27 < / StateCode >
< FinancialYear > 2013 < / FinancialYear >
< D. epartmentCode > G < / DepartmentCode >
< BudgetCode > 0040000000000 < / BudgetCode >
< StateSchemeCode > 24016241 < / StateSchemeCode >
< CPSMSSchemeCode > 0404 < / CPSMSSchemeCode >
< CreatedDate > 22/03/2013 < / CreatedDate >
< / CPSMSStateSchemeMapping >
解决方案
以下是解决方案。
// 通过使用此方法,我们可以将datatable转换为xml
public string ConvertDatatableToXML(DataTable dt)
{
Memory Stream str = new MemoryStream();
dt.WriteXml(str, true );
str.Seek( 0 ,SeekOrigin.Begin);
StreamReader sr = new StreamReader(str);
string xmlstr;
xmlstr = sr.ReadToEnd();
return (xmlstr);
}
只需将Datatable作为参数传递给此方法即可获得xml格式的数据。
你可以尝试这个链接:
http://stackoverflow.com/questions/1564541/how-to-convert-记录在一个表到xml格式使用-t-sql [ ^ ]
http://stackoverflow.com/questions/18353250/convert -sql-table-to-xml [ ^ ]
Hi,
I have data table in that table have a data that data will be convert in to xml format like
inside tag
example
<CPSMSStateSchemeMapping>
<StateCode>27</StateCode>
<FinancialYear>2013</FinancialYear>
<DepartmentCode>G</DepartmentCode>
<BudgetCode>0040000000000</BudgetCode>
<StateSchemeCode>24016241</StateSchemeCode>
< CPSMSSchemeCode>0404</CPSMSSchemeCode >
<CreatedDate >22/03/2013</CreatedDate>
</CPSMSStateSchemeMapping>
解决方案
Hi,
Here is the solution.
// By using this method we can convert datatable to xml public string ConvertDatatableToXML(DataTable dt) { MemoryStream str = new MemoryStream(); dt.WriteXml(str, true); str.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(str); string xmlstr; xmlstr = sr.ReadToEnd(); return (xmlstr); }
Just pass the Datatable as the parameter to this method you will be getting data in xml format.
you can try this link:
http://stackoverflow.com/questions/1564541/how-to-convert-records-in-a-table-to-xml-format-using-t-sql[^]
http://stackoverflow.com/questions/18353250/convert-sql-table-to-xml[^]
这篇关于我在sql表中有数据,数据将在标签内转换为xml格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文