1读取xml转换为dataset
private static DataSet FromXmlFileToDataSet()
{
StringReader StrStream = null;
XmlTextReader Xmlrdr = null;
try
{
XmlDocument xmldoc = new XmlDocument();
//加载Xml文件
xmldoc.LoadXml(xmlpath);
DataSet ds = new DataSet();
//读取文件中的字符流
StrStream = new StringReader(xmldoc.InnerXml);
//获取StrStream中的数据
Xmlrdr = new XmlTextReader(StrStream);
//ds获取Xmlrdr中的数据
ds.ReadXml(Xmlrdr);
return ds;
}
catch (Exception e)
{
throw e;
}
finally
{
//释放资源
if (Xmlrdr != null)
{
Xmlrdr.Close();
StrStream.Close();
StrStream.Dispose();
}
}
}