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();
}
}
|