您的位置:首页 > 编程语言 > C#

C# 获取xml数据,并转换为dataset

2014-01-08 09:46 309 查看
//获取xml数据,并转换为dataset
public static DataSet getConfig(string strXmlPath)
{
string filePath = GetPhysicalPath();
DataSet ds= ConvertXMLFileToDataSet(GetXmlFullPath(filePath));
return ds;
}
//将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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# 获取 xml 转换 dataset