What I’m trying to do is to write a generic rss reader that I plug in any URL into without worry if the feed has all the common properties. For instance in my example below I’m looking for pubDate, however if no pubDate exists in the xml I’d like to return the current Date. I cannot seem to get the syntax right though. Any suggestions?
Dim xmldoc As New XDocument
xmldoc = XDocument.Load(url)
Dim feeds = From feed In xmldoc.Descendants("item") Select New With { _
Key .Title = feed.Element("title").Value, _
Key .Link = feed.Element("link").Value, _
Key .Description = feed.Element("description").Value, _
Key .PubDate = If(feed.Element("pubDate").Value Is Nothing, Date.Now.ToString, feed.Element("pubDate").Value)}
For Each item In feeds
Response.Write("<a href=""" & item.Link & """ target=""_blank"">" & item.Title & "</a> - " & item.PubDate & "<br />")
Response.Write(item.Description & "<hr />")
Next
instead of
feed.Element("pubDate").Value Is Nothingwritefeed.Element("pubDate") Is Nothing!