我已經在我的應用程序中追溯到下面定時定位的代碼段落。我知道這會是一個慢點,但每個請求平均需要1秒。我後面的xml位總是在第一個標籤中,所以我不認爲這是下載時間讓我感到滿意。XML閱讀器性能
Stopwatch stopwatch = new Stopwatch();
XmlTextReader reader = new XmlTextReader("http://steamcommunity.com/id/test?xml=1");
stopwatch.Reset();
stopwatch.Start();
while (reader.Read()) {
if (reader.Name.Equals("steamID64")) {
reader.Read();
stopwatch.Stop();
time = stopwatch.ElapsedMilliseconds();
return Convert.ToInt64(reader.Value);
}
}
是否有更快的方式來讀取我想要的標籤或我被服務器限制我正在下載xml文件?
謝謝。
嘗試使用XPathNavigator對象 - http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.aspx – 2010-08-26 21:50:14
XmlTextReader是一個Disposable對象。 – 2010-08-26 21:51:43
@Yuriy,你的意思是使用reader.close()?我這樣做,只是沒有包含在上面的代碼片段中。 – Radu 2010-08-26 21:55:17