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();
}
}
相关文档:
这是一个用c#控制台程序下, 用XmlDocument 进行XML操作的的例子,包含了查询、增加、修改、删除、保存的基本操作。较完整的描述了一个XML的整个操作流程。适合刚入门.net XML操作的朋友参考和学习。
假设有XML文件:books.xml
Xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<books>
< ......
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 ......
今天是上课的第一天,没想到第一天就讲了那么多的东西,看了看老师的PPT,发现东西虽然多,但是都不难理解,还是比较容易的。哈哈,得益于在传智基础班的锤炼,英明的决定就是从头学起。
刚过完春节老方的话还是说的不是很流利啊(要加强普通话练习喔 ......
1.在JSP中生成动态XML
可以使用JSP生成XML,使用CSS或者XSL转换和显示XML;
只要在静态的XML文档模板中加入Java代码和JSP标记,XML就可以有静变动,产生动态的内容,生成XML文档的方法很简单,只需要在文件中使用指令contenttype,如<%@ page contenttype="text/xml"%>;
在XML文档中同样可以使 ......
1、初始化
Load 导入一个XML文件到CMarkup的对象中,并对它进行解析。类似C#的Load。
SetDoc 从字符串中导入XML数据,并对它解析。类似C#的LoadXml。
2、输出
Save 将XML数据写入文件中。类似C#的Save。
GetDoc 将整个XML数据文档作为字符串返回。
3、改变当前位置
FindElem 定位到下一个元素,可能和一个标签名或路 ......