DataSet(DataTable)与XML互转
using System;
using System.Data;
using System.IO;
using System.Xml;
using System.Text;
// 相应C#代码:
private string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new XmlTextWriter(stream, Encoding.Default);
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
UTF8Encoding utf = new UTF8Encoding();
return utf.GetString(arr).Trim();
}
catch
{
return String.Empty;
}
finally
{
if (writer != null) writer.Close();
}
}
private DataSet ConvertXMLToDataSet(string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
DataSet xmlDS = new DataSet();
stream = new StringReader(xmlData);
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
return xmlDS;
}
catch (Exception ex)
{
string strTest = ex.Message;
return null;
}
finally
{
if (reader != null)
reader.Close();
}
}
相关文档:
以前在博客上发过,经人提醒DataSet已自带读写XML的功能,于是便删了,
不过在实践中感觉封装一层后,使用起来还是蛮方便的。故再次重发。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Xml;
namespace XmlDesign
{
class XmlDatasetC ......
VC++中操作XML(MFC、SDK)
2009年01月07日 星期三 22:33
XML在Win32程序方面应该没有在Web方面应用得多,很多
Win32程序也只是用XML来存存配置信息而已,而且没有足够
的好处的话还不如用 ini。VC++里操作XML有两个库可以用:
MSXML和XmlLite。MSXML又细分了两种接口:DOM和SAX2。XP没自带有 XmlLite,只自带有2.x、3 ......
一个定义Email的例子
<?xml version="1.0">
<!DOCTYPE message[
<!ELEMENT message(header,body,signature,footer)> --定义了message的子元素
<!ELEMENT header(date,from,to,subject,banner)> --header还有子元素
<!ELEMENT ......
今天是上课的第一天,没想到第一天就讲了那么多的东西,看了看老师的PPT,发现东西虽然多,但是都不难理解,还是比较容易的。哈哈,得益于在传智基础班的锤炼,英明的决定就是从头学起。
刚过完春节老方的话还是说的不是很流利啊(要加强普通话练习喔 ......
你知道XML文件吧?(不知道的GOOGLE去!)那你听说过在XML里书写SQL语句吗?换句话说,把你的项目里所有SQL语句存储在XML文件里,你听说过吗?你做过吗?
我头次听说是小艾告诉我的,我敢肯定他是个这方面的高手,呵呵(赞一个,到此为止!)
那给你展示一下,在XML里书写SQL语句吧
<commands>
<comman ......