Search code examples
razorrssxml-parsinggrowl-for-windows

growl for windows - rss feed not being parsed - format error?


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?


Solution

  • 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 [email protected]("</link>")

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