2012-12-25 86 views
0

我想要提取從我的XML文檔元素的最後10,我用這個代碼解析它:提取最近10個從XML文檔元素

slideView.ItemsSource = 
    from channel in xmlItems.Descendants("album") 
    let id = channel.Element("catid") 
    let tit = channel.Element("name") 
    let des = channel.Element("picture") 
    orderby (int) id descending 
    select new onair 
    { 
     title = tit == null ? null : tit.Value, 
     photo = des == null ? null : des.Value, 
    }; 

幫助,請:) 感謝

回答

0

此代碼將返回有序最後10種元素的catid

slideView.ItemsSource = 
    xmlItems.Descendants("album") 
      .OrderByDescending(channel => (int)channel.Element("catid")) 
      .Select(channel => new onair 
      { 
       title = (string)channel.Element("name"), 
       photo = (string)channel.Element("picture") 
      }).Take(10); 

同樣的,查詢語法(當然,幾乎查詢語法 - 那裏是採取運營商沒有關鍵字):

slideView.ItemsSource = 
    (from channel in xmlItems.Descendants("album")  
    orderby (int)channel.Element("catid") descending 
    select new onair 
    { 
     title = (string)channel.Element("name"), 
     photo = (string)channel.Element("picture") 
    }).Take(10); 
+0

感謝,運作良好,但我'嘗試添加一個按鈕,如果用戶點擊它,因爲我對XML許多elemnts是加載下一個10個元素:/任何想法嗎? –

+0

@MeriemBenMrad你可以使用Skip(pageIndex * pageSize).Take(pageSize)' –

+0

你能解釋一下嗎?請給我一個例子。? –