以FileShare.Read形式读XML文件:

string hotspotXmlStr = string.Empty;
try
{
Stream fileStream = new FileStream(context.Server.MapPath("../data/Hotspot.xml"), FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8);
hotspotXmlStr = streamReader.ReadToEnd();
streamReader.Dispose();
}
catch (Exception ex)
{
logger.Error("读取XML文件Hotspot.xml出现异常!");
logger.Error("异常描述:\t" + ex.Message);
logger.Error("引发异常的方法:\t" + ex.TargetSite);
logger.Error("异常堆栈:\t" + ex.StackTrace);
}

XML与DataSet相互转换的类(出处):

class XmlDatasetConvert
{
//将xml对象内容字符串转换为DataSet
public static DataSet ConvertXMLToDataSet(string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
DataSet xmlDS = new DataSet();
stream = new StringReader(xmlData);
//从stream装载到XmlTextReader
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
return xmlDS;
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (reader != null) reader.Close();
}
} //将xml文件转换为DataSet
public static DataSet ConvertXMLFileToDataSet(string xmlFile)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
XmlDocument xmld = new XmlDocument();
xmld.Load(xmlFile); DataSet xmlDS = new DataSet();
stream = new StringReader(xmld.InnerXml);
//从stream装载到XmlTextReader
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
//xmlDS.ReadXml(xmlFile);
return xmlDS;
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (reader != null) reader.Close();
}
} //将DataSet转换为xml对象字符串
public static string ConvertDataSetToXML(DataSet xmlDS)
{
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(, SeekOrigin.Begin);
stream.Read(arr, , count); UnicodeEncoding utf = new UnicodeEncoding();
return utf.GetString(arr).Trim();
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (writer != null) writer.Close();
}
} //将DataSet转换为xml文件
public 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(, SeekOrigin.Begin);
stream.Read(arr, , count); //返回Unicode编码的文本
UnicodeEncoding utf = new UnicodeEncoding();
StreamWriter sw = new StreamWriter(xmlFile);
sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sw.WriteLine(utf.GetString(arr).Trim());
sw.Close();
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (writer != null) writer.Close();
}
} }

DataSet查询,参考DataTable.Select 方法

XML与DataSet相互转换,DataSet查询的更多相关文章

  1. Springboot中使用Xstream进行XML与Bean 相互转换

    在现今的项目开发中,虽然数据的传输大部分都是用json格式来进行传输,但是xml毕竟也会有一些老的项目在进行使用,正常的老式方法是通过获取节点来进行一系列操作,个人感觉太过于复杂.繁琐.推荐一套简单的 ...

  2. Hibernate中:不看数据库,不看XML文件,不看查询语句,怎么样能知道表结构?

    Hibernate中:不看数据库,不看XML文件,不看查询语句,怎么样能知道表结构? 解答:可以看与XML文件对应的域模型.

  3. from flyai.dataset import Dataset 报错

    from flyai.dataset import Dataset 报错 No module name 'flyai' ​ 先找到ide中使用的Python对应的pip的位置. ​ windows用户 ...

  4. XML IList<T> TO DataSet TO DataTable 相互转换

    //遍历XML 获得 DataSet //XmlTextReader static void Main(string[] args) { string xmlData = @"D:\stud ...

  5. c#解析XML到DATASET及dataset转为xml文件函数

    //将xml对象内容字符串转换为DataSet         public static DataSet ConvertXMLToDataSet(string xmlData)         { ...

  6. ASP.NET中把xml转为dataset与xml字符串转为dataset及dataset转为xml的代码

    转自:http://www.cnblogs.com/_zjl/archive/2011/04/08/2009087.html XmlDatasetConvert.csusing System;usin ...

  7. [C#]Winform后台提交数据且获取远程接口返回的XML数据,转换成DataSet

    #region 接口返回的Xml转换成DataSet /// <summary> /// 返回的Xml转换成DataSet /// </summary> /// <par ...

  8. C#中Json和List/DataSet相互转换

    #region List<T> 转 Json        /// <summary>        /// List<T> 转 Json        /// & ...

  9. 泛型集合与DataSet相互转换

    一.泛型转DataSet /// <summary> /// 泛型集合转换DataSet /// </summary> /// <typeparam name=" ...

随机推荐

  1. js解决快速回车重复订单提交(客户端方式)

    Html代码: <form action="order_add_data.php" method="post" name="order_adds ...

  2. clearfix 清除浮动的问题

    今天看一篇博文,发现其实有很多方法实现清除浮动,各有利弊 采用伪类:after进行后续空制的高度位零的伪类层清除 采用CSS overflow:auto的方式撑高 采用CSS overflow:hid ...

  3. PHP Simple HTML DOM Parser Manual-php解析DOM

    PHP Simple HTML DOM Parser Manual http://www.lupaworld.com/doc-doc-api-770.html PHP Simple HTML DOM ...

  4. 每天一个Linux命令(3): cd

    Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. 所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 1.  ...

  5. iOS 5.0 后UIViewController新增:willMoveToParentViewController和didMoveToParentViewCon

    在iOS 5.0以前,我们在一个UIViewController中这样组织相关的UIView   在以前,一个UIViewController的View可能有很多小的子view.这些子view很多时候 ...

  6. Python 字典(Dictionary) get()方法

    描述 Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值. 语法 get()方法语法: dict.get(key, default=None) 参数 ...

  7. Jquery 设置style:display 通过ID隐藏区域

    $("#id").css('display','none'); $("#id").css('display','block'); 或 $("#id&q ...

  8. codeforces 340B Maximal Area Quadrilateral(叉积)

    事实再一次证明:本小菜在计算几何上就是个渣= = 题意:平面上n个点(n<=300),问任意四个点组成的四边形(保证四条边不相交)的最大面积是多少. 分析: 1.第一思路是枚举四个点,以O(n4 ...

  9. hibernate的组成部分

    持久化类 实现对应的序列化接口 必须有默认的构造函数 持久化类的属性不能使用关键字 标示符 映射文件 类型 java类型和hibernate类型 主键的产生器 increment identity a ...

  10. C++ STL算法系列5---equal() , mismatch()

    equal和mismatch算法的功能是比较容器中的两个区间内的元素.这两个算法各有3个参数first1,last1和first2.如果对 于区间[first1,last1)内所有的first1+i, ...