We help IT Professionals succeed at work.
Get Started

Creating RSS Feed in VB.net, How to add line breaks to output

Last Modified: 2013-11-18
I am using vb.net (vs 2008) to create an RSS feed from SQL Server 2008 database.

I have been successful reading the data from the db and writing to an RSS feed. I would like help formating the RSS feed.

Each record that I pull from the data base contains 5 fields. I am usingthe first field as the title of the item on the RSS feed. I would like each field to be written on a new line, but I have not been able to get it to do anything but print all the fields in the same line.

I have attached the code I am using to create the RSS feed. In the code I included comments where I would like a new line to be inserted in the output.

I have also attached one image showing how the output looks now and a second image of output from a similar RSS feed that I would like my feed to look like.

Thanks any help you can provide.

 This is the output I am getting now This is similar to how I want the output to look.
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        'send document as response      
        context.Response.ContentType = "text/xml"
        context.Response.ContentEncoding = System.Text.Encoding.UTF8

        'create RSS xml document 
        Dim xml As New XmlTextWriter(context.Response.OutputStream, Encoding.UTF8)
        xml.Formatting = Formatting.Indented
        xml.WriteAttributeString("version", "2.0")
        'create feed header section xml.WriteStartElement("channel") 
        xml.WriteElementString("title", "Data Feed")
        xml.WriteElementString("link", "http://www.website.com")
        xml.WriteElementString("description", "View last 90 days of data for the selected asset.")
        xml.WriteElementString("language", "en-us")
        xml.WriteElementString("pubDate", DateTime.UtcNow.ToString("r"))
        xml.WriteElementString("lastBuildDate", DateTime.UtcNow.ToString("r"))
        xml.WriteElementString("managingEditor", "john@website.com")
        xml.WriteElementString("webMaster", "john@website.com")
        xml.WriteElementString("ttl", "1")

        'get data rows
        Dim ds As DataSet = GetData()
        'add rows to feed 
        Dim row As DataRow
        For Each row In ds.Tables(0).Rows
            xml.WriteElementString("title", row("PointOfInterestDescription"))
            xml.WriteElementString("link", "www.website.com")
            'output rows of data 

            xml.WriteElementString("description", "PointOfInterestCode:  ")
            xml.WriteElementString("description", row("PointOfInterestCode"))
            'Would like new line here
            xml.WriteElementString("description", "ObservationTime:  ")
            xml.WriteElementString("description", CType(row("ObservationTime"), DateTime).ToString("G"))
            'Would like new line here
            xml.WriteElementString("description", "ObservationValue:  ")
            xml.WriteElementString("description", row("ObservationValue"))
            'Would like new line here
            xml.WriteElementString("description", "EmployeeCode:  ")
            xml.WriteElementString("description", row("EmployeeCode"))
            xml.WriteElementString("pubDate", CType(row("ObservationTime"), DateTime).ToString("G"))

        'close channel     
        'close rss      
        'close document      
    End Sub

Open in new window

Watch Question
Most Valuable Expert 2011
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE