私はxmlファイルにいくつかの項目を持っていますが、1つだけ、最初の読み込みです。私は何が起こっているのか分からない。しかし、私がe.Result文字列を出力すると、すべての項目が表示されます。どういうわけか、項目はXMLファイルを解析しません。WebClientを使用してSilverlightアプリケーションにXMLデータをロードする方法は?
<?xml version="1.0" encoding="utf-8" ?>
<Images>
<Image>hello.jpg</Image>
<Image>goodbye.jpg</Image>
<Image>flower.jpg</Image>
<Image>bird.jpg</Image>
</Images>
コード:のみ1 "画像" の要素は、XML文書にあります
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("Data.xml", UriKind.RelativeOrAbsolute));
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string result = e.Result;
byte[] byteArray = Encoding.UTF8.GetBytes(result);
MemoryStream stream = new MemoryStream(byteArray);
int index = 0;
foreach (XElement element in xdoc.Descendants("Images").ToList())
{
index += 1;
}
Label l = new Label();
l.Content = index.ToString();
listBox1.Items.Add(l);
}
// outputs 1 - WTF?
XMLファイルの一部も表示できますか?おそらくあなたが探しているのはの**子ども**ですか? –