//获取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
最新推荐文章于 2024-04-13 20:09:58 发布
本文介绍了一种将XML文件转换为DataSet的方法,包括获取XML文件路径、读取XML内容并将其装载到DataSet中等步骤。
1万+

被折叠的 条评论
为什么被折叠?



