2011-08-04 11 views
1

私は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? 
+0

XMLファイルの一部も表示できますか?おそらくあなたが探しているのはの**子ども**ですか? –

答えて

3

、そうxdoc.Descendants("Images")のみ1つの要素を返します。個別の<Image>要素が必要な場合は、xdoc.Descendants("Image")またはxdoc.Descendants("Images").Elements()

+0

ありがとう!私を助けてくれました! – marko

関連する問題