2

So I'm attempting to use the custom subscriber SDK for Growl for Windows. Trying to dynamically create a RSS feed. Using C#, with Razor views. This is a sample of what the view looks like to which I am pointing the url of the subscriber:

@model GrowlExtras.Subscriptions.FeedMonitor.FeedItem
<?xml version="1.0" encoding="UTF-8" ?>

@{
    Response.ContentType = "application/rss+xml";
    ViewBag.Title = "Feed";
}

<rss version="2.0">
    <channel>
        <title>@Model.Title</title>
        <link>@Url.Action("Feed", "Home", null, "http")</link>
        <description>@Model.Description</description>
        <lastBuildDate>@Model.PubDate</lastBuildDate>
        <language>en-us</language>
    </channel>
</rss>

This page is accessed locally (for now) using this url: http://localhost:2751/Home/Feed. So, I'm putting this url in as the "Feed Url:" on the "subscribe to notifications popup".. but getting an error "could not parse feed" and the OpenReadCompletedEventArgs e result is throwing the exception "OpenReadCompletedEventArgs '(e.Result).Length' threw an exception of type 'System.NotSupportedException'"

Any help welcome! Am I barking up the wrong tree completely here, or just missing something with the formatting of the feed file? Don't suppose it has something to do with the fact that the page is hosted locally at the moment?

JPThorne
  • 610
  • 11
  • 17

2 Answers2

1

The real answer is that Razor verifies that what you are trying to write is valid HTML. If you fail to do so, Razor fails.

Your code tried to write incorrect HTML:

If you look at the documentation of link tag in w3schools you can read the same thing expressed in different ways:

  • "The element is an empty element, it contains attributes only."
  • "In HTML the tag has no end tag."

What this mean is that link is a singleton tag, so you must write this tag as a self-closing tag, like this:

<link atrib1='value1' attrib2='value2' />

So you can't do what you was trying to do: use an opening and a closing tag with contents inside.

That's why Razor fails to generate this your <xml> doc.

But there is one way you can deceive Razor: don't let it know that you're writing a tag, like so:

@Html.Raw("<link>")--your link's content--@Html.Raw("</link>")

Remember that Razor is for writing HTML so writing XML with it can become somewhat tricky.

JotaBe
  • 38,030
  • 8
  • 98
  • 117
0

Right. Got this one sorted now.

A lot more digging was required! The page above did not parse correctly as a valid xml page, for example - html tags are being generated here, and this throws the rss parser of the plugin in question.

What I ended up doing was to use the built in RSS Syndication classes, and some help from these posts/related answers on the topic.

<http://stackoverflow.com/a/825016/1152015>
<http://stackoverflow.com/a/684518/1152015>
<http://stackoverflow.com/a/1292769/1152015>
<http://stackoverflow.com/a/2690302/1152015>
<http://stackoverflow.com/a/3098559/1152015>
<http://msdn.microsoft.com/en-us/library/bb412174>

So, to clarify - I had the code to consume a rss feed, but the page being generated dynamically was not being parsed correctly by the parser I was using.

JPThorne
  • 610
  • 11
  • 17