如何閱讀從wp7應用程序使用c#的「rss飼料」:「http://www.nyc.gov/apps/311/311Today.rss」?閱讀rss飼料wp7與c#
我的XAML代碼:
<ListBox HorizontalAlignment="Left" Margin="10,10,0,0" Name="listBox1" VerticalAlignment="Top" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top">
<TextBlock x:Name="titleTxt" Height="30" Text="{Binding Title}" VerticalAlignment="Bottom" />
<TextBlock x:Name="dateTxt" Height="30" Text="{Binding Date}" />
<TextBlock x:Name="descTxt" Height="30" Text="{Binding Desc}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的C#代碼:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
XDocument xDoc = XDocument.Load("http://www.nyc.gov/apps/311/311Today.rss");
XNamespace content = XNamespace.Get("http://purl.org/rss/1.0/modules/content/");
var items = xDoc.Descendants("item")
.Select(i => new
{
Title = i.Element("title").Value,
Date = DateTime.Parse(i.Element("pubDate").Value),
Desc = i.Element(content + "encoded").Value,
})
.ToArray();
listBox1.ItemsSource = items;
}
那麼[?你嘗試過什麼(http://www.whathaveyoutried.com) – 2012-07-23 20:07:33
@ErikPhilips我已經從MSDN嘗試了樣本代碼,但什麼都沒有來。 – Shan 2012-07-23 20:09:27