DataSet与xml文件的互相转换
http://www.cnblogs.com/long2006sky/articles/1258731.html
DataSet转换为xml文件
//将DataSet转换为xml文件
private static void ConvertDataSetToXMLFile(DataSet xmlDS, string xmlFile)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
//从stream装载到XmlTextReader
writer = new XmlTextWriter(stream, Encoding.Unicode);
//用WriteXml方法写入文件.
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
//返回Unicode编码的文本
相关文档:
JAXBContext jc = JAXBContext.newInstance(ICPBuildSummaryXO.class);
Unmarshaller u = jc.createUnmarshaller();
ICPBuildSummaryXO xo = (ICPBuildSummaryXO) u.unmarshal(node);
ICPBuildSummary summary = new ICPBuildSummary();
Bean ......
实例说明会更清楚些,假设有如下XML文件:
File: message_hutaow.xml
<?xml version="1.0" encoding="UTF-8"?>
<hutaow:Message version="1.0" xmlns:hutaow="http://wangtao.cublog.cn">
<hutaow:Head>
<hutaow:Date>20080502</hutaow:Date>
<hutaow:Source>
......
Query:
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(".\\db\\dbGuest.xml"));
//User是XML根节点,Name字节点
lbEmail.Text =
doc.SelectSingleNode("//User ......