How to add item image information to rss news feed using ASP.NET

Posted on 2014-09-04
Last Modified: 2014-09-05
I'm trying to include an image in the rss feed xml I'm generateing using XmlTextWriter. I have two problems:

1. What is the correct output format for this information? I found one source that suggests it should be formatted as follows:

<item>...<media:content medium="image" url=""></media:content></item>

But other sources seem to suggest I should be using the enclosure element.

2. I tried to use the following code to generate my xml but when I look at it via the browser, I get "Reference to undeclared namespace prefix: 'media'."

Here's the code:
        Response.ContentType = "text/xml"
        Dim xtwFeed As XmlTextWriter = New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        'The mandatory rss tag

        xtwFeed.WriteAttributeString("version", "2.0")

        'The channel tag contains RSS feed details
        xtwFeed.WriteElementString("title", "My News :: News")
        xtwFeed.WriteElementString("link", "")
        xtwFeed.WriteElementString("description", "The latest news from My domain.")
        xtwFeed.WriteElementString("copyright", "Copyright 2010 My Group. All rights reserved.")
        xtwFeed.WriteElementString("category", "News")
        xtwFeed.WriteElementString("ttl", "120")

        xtwFeed.WriteElementString("url", "")
        xtwFeed.WriteElementString("title", "The latest news from My Group.")
        xtwFeed.WriteElementString("link", "")

        Dim buildDate As Date = TimeZoneInfo.ConvertTimeToUtc(Now())
        xtwFeed.WriteElementString("lastBuildDate", buildDate.ToString("R"))
        For Each dr As DataRow In T.Rows
            xtwFeed.WriteElementString("title", FormatForXML(dr.Item("nevTitle").ToString()))
            xtwFeed.WriteElementString("description", FormatForXML(dr.Item("nevDesc").ToString()))
            xtwFeed.WriteElementString("link", "" & dr.Item("nevID"))
            Dim d As Date = TimeZoneInfo.ConvertTimeToUtc(dr.Item("nevStartDate"))
            xtwFeed.WriteElementString("pubDate", d.ToString("R"))

            If Not DBNull.Value.Equals(dr.Item("nevPic1")) Then
                xtwFeed.WriteAttributeString("medium", "image")
                xtwFeed.WriteAttributeString("url", dr.Item("nevPic1"))
            End If


        'Close all tags 

Open in new window

This code writes the media:content as <media:content medium="image" url="/images/NewsEvents/Image01.jpg" />.

My goal is to use this feed as the input to DevExpress's ASPxNewsControl.

Thank you for any assistance you can provide.
Question by:ZekeLA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

ZekeLA earned 0 total points
ID: 40305887
I found the problem. I needed to add the following code after the line with the 2.0 version attribute:

xtwFeed.WriteAttributeString("xmlns:media", "")    ' note that media must be spelled as lowercase

Open in new window


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question