将xml对象内容字符串转换为DataSet

前端之家收集整理的这篇文章主要介绍了将xml对象内容字符串转换为DataSet前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//将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();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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();
}
}
原文链接:https://www.f2er.com/xml/297643.html

猜你在找的XML相关文章