-1
我今天爲我的C#應用程序製作了XML文件。
XML(我的推杆在引擎收錄,「導致其還挺大的XML代碼,不好意思):Pastebin
和C#XML,XDocument.Parse和foreach XElement
private void web_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument doc = XDocument.Parse(e.Result);
foreach (XElement xe in doc.Root.Element("builds").Element("build").Element("items").Elements("item"))
{
string s0 = xe.Element("name").ToString();
string s1 = xe.Element("uri").ToString();
string[] s2 = new string[2];
s2[0] = s0;
s2[1] = s1;
ListViewItem lvi = new ListViewItem(s2);
listView1.Items.Add(lvi);
}
}
}
內部的代碼,我得到錯誤 - Object reference not set to an instance of an object.
或者有時根本
調試你的代碼。其中一個'.Element(name)'返回null。所以'null.SomeMethod'會拋出異常。 – I4V
試試doc.Descendants(「name」); – Jonesopolis
@ I4V調試並沒有給我任何意義 – user2713690