我需要从互联网加载许多XML文件。但为了进行更快速的测试,我已经下载了超过500个以下格式的文件。
<player-profile>
<personal-information>
<id>36</id>
<fullname>Adam Gilchrist</fullname>
<majorteam>Australia</majorteam>
<nickname>Gilchrist</nickname>
<shortName>A Gilchrist</shortName>
<dateofbirth>Nov 14, 1971</dateofbirth>
<battingstyle>Left-hand bat</battingstyle>
<bowlingstyle>Right-arm offbreak</bowlingstyle>
<role>Wicket-Keeper</role>
<teams-played-for>Western Australia, New South Wales, ICC World XI, Deccan Chargers, Australia</teams-played-for>
<iplteam>Deccan Chargers</iplteam>
</personal-information>
<batting-statistics>
<odi-stats>
<matchtype>ODI</matchtype>
<matches>287</matches>
<innings>279</innings>
<notouts>11</notouts>
<runsscored>9619</runsscored>
<highestscore>172</highestscore>
<ballstaken>9922</ballstaken>
<sixes>149</sixes>
<fours>1000+</fours>
<ducks>0</ducks>
<fifties>55</fifties>
<catches>417</catches>
<stumpings>55</stumpings>
<hundreds>16</hundreds>
<strikerate>96.95</strikerate>
<average>35.89</average>
</odi-stats>
<test-stats>
.
.
.
</test-stats>
<t20-stats>
.
.
.
</t20-stats>
<ipl-stats>
.
.
.
</ipl-stats>
</batting-statistics>
<bowling-statistics>
<odi-stats>
<matchtype>ODI</matchtype>
<matches>378</matches>
<ballsbowled>58</ballsbowled>
<runsgiven>64</runsgiven>
<wickets>3</wickets>
<fourwicket>0</fourwicket>
<fivewicket>0</fivewicket>
<strikerate>19.33</strikerate>
<economyrate>6.62</economyrate>
<average>21.33</average>
</odi-stats>
<test-stats>
.
.
.
</test-stats>
<t20-stats>
.
.
.
</t20-stats>
<ipl-stats>
.
.
.
</ipl-stats>
</bowling-statistics>
</player-profile>
我正在使用
XmlNodeList list = _document.SelectNodes("/player-profile/batting-statistics/odi-stats");
然后使用
foreach
循环此列表。foreach (XmlNode stats in list)
{
_btMatchType = GetInnerString(stats, "matchtype"); //it returns null string if node not availible
.
.
.
.
_btAvg = Convert.ToDouble(stats["average"].InnerText);
}
即使我离线加载所有文件,解析速度仍然很慢。有没有更快的好方法来解析它们?或者是SQL的问题吗?我正在使用DataSets、TableAdapters和插入命令将从XML提取的所有数据保存到数据库中。
编辑:现在,请为上面的文档提供一些XmlReader代码。目前,我已经完成了这个。
void Load(string url)
{
_reader = XmlReader.Create(url);
while (_reader.Read())
{
}
}
可用的XmlReader方法令人困惑。我需要完整地获取击球和投球统计数据,击球和投球统计数据不同,而ODI、T20、IPL等在投球和击球中是相同的。