I have some code that writes a feed in .aspx format and would like to write to xml (rss) format.
How do I modify this code so that the feed would have the xml extention ex: feed.xml not feed.aspx.
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Xml
Imports System.Text
Imports System.Data.SqlClient
Partial Public Class Employees
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
' Clear the response buffer contents
Response.Clear()
Response.ContentType = "text/xml"
Dim rssFeed As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
'writing RSS tags
rssFeed.WriteStartDocument()
rssFeed.WriteStartElement("rss")
rssFeed.WriteAttributeString("version", "2.0")
rssFeed.WriteStartElement("channel")
rssFeed.WriteElementString("title", "Employee Details")
rssFeed.WriteElementString("link", "http://localhost:63620/rss/")
rssFeed.WriteElementString("description", "Details of Employees")
' create sql connection and connect to database
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RSS.mdf;Integrated Security=True;User Instance=True")
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select * from Employee"
cmd.Connection = con
con.Open()
Dim dReader As SqlDataReader
dReader = cmd.ExecuteReader()
While dReader.Read()
rssFeed.WriteStartElement("item")
rssFeed.WriteElementString("title", dReader("Title").ToString())
rssFeed.WriteElementString("description", dReader("Location").ToString())
rssFeed.WriteElementString("link", dReader("Link").ToString())
rssFeed.WriteElementString("pubDate", DateTime.Now.ToString())
rssFeed.WriteEndElement()
End While
dReader.Close()
con.Close()
rssFeed.WriteEndElement()
rssFeed.WriteEndElement()
rssFeed.WriteEndDocument()
rssFeed.Flush()
rssFeed.Close()
Response.[End]()
End If
End Sub
End Class
ds.ReadXML(xmlFilePath) //reads the xml and loads Tables, Rows and columns format so to read first columns value of first row and first table then statement would be Tabless[0].Rows[0].Columns[0] format
ds.WriteXml(xmlFilePath) //save data into xml format
How do I modify this code so that the feed would have the xml extention ex: feed.xml not feed.aspx.
Hi,
If you are running with aspx page,I'm afraid you cannot change that because the default page's name's suffix name is *.aspx;however you can use UrlWriter to rewrite the aspx page's index route like this:http://urlrewriter.net/index.php/download
deongee
Member
21 Points
128 Posts
how to write xml in rss format from dataset
Jul 04, 2012 03:22 AM|LINK
I have some code that writes a feed in .aspx format and would like to write to xml (rss) format.
How do I modify this code so that the feed would have the xml extention ex: feed.xml not feed.aspx.
Imports System.Data Imports System.Configuration Imports System.Collections Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Xml Imports System.Text Imports System.Data.SqlClient Partial Public Class Employees Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then ' Clear the response buffer contents Response.Clear() Response.ContentType = "text/xml" Dim rssFeed As New XmlTextWriter(Response.OutputStream, Encoding.UTF8) 'writing RSS tags rssFeed.WriteStartDocument() rssFeed.WriteStartElement("rss") rssFeed.WriteAttributeString("version", "2.0") rssFeed.WriteStartElement("channel") rssFeed.WriteElementString("title", "Employee Details") rssFeed.WriteElementString("link", "http://localhost:63620/rss/") rssFeed.WriteElementString("description", "Details of Employees") ' create sql connection and connect to database Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RSS.mdf;Integrated Security=True;User Instance=True") Dim cmd As New SqlCommand() cmd.CommandType = CommandType.Text cmd.CommandText = "Select * from Employee" cmd.Connection = con con.Open() Dim dReader As SqlDataReader dReader = cmd.ExecuteReader() While dReader.Read() rssFeed.WriteStartElement("item") rssFeed.WriteElementString("title", dReader("Title").ToString()) rssFeed.WriteElementString("description", dReader("Location").ToString()) rssFeed.WriteElementString("link", dReader("Link").ToString()) rssFeed.WriteElementString("pubDate", DateTime.Now.ToString()) rssFeed.WriteEndElement() End While dReader.Close() con.Close() rssFeed.WriteEndElement() rssFeed.WriteEndElement() rssFeed.WriteEndDocument() rssFeed.Flush() rssFeed.Close() Response.[End]() End If End Sub End ClassMudasir.Khan
All-Star
15346 Points
3142 Posts
Re: how to write xml in rss format from dataset
Jul 04, 2012 03:47 AM|LINK
Dataset support
ds.ReadXML(xmlFilePath) //reads the xml and loads Tables, Rows and columns format so to read first columns value of first row and first table then statement would be Tabless[0].Rows[0].Columns[0] format
ds.WriteXml(xmlFilePath) //save data into xml format
deongee
Member
21 Points
128 Posts
Re: how to write xml in rss format from dataset
Jul 04, 2012 04:20 AM|LINK
I'm very new at this, can you collaborate a little more.
deongee
Member
21 Points
128 Posts
Re: how to write xml in rss format from dataset
Jul 04, 2012 05:23 PM|LINK
Does anyone have a link to a tutorial or example of what I'm talking about?
deongee
Member
21 Points
128 Posts
Re: how to write xml in rss format from dataset
Jul 04, 2012 05:45 PM|LINK
this code is already reading from the the database. How do I write to an xml file from the database table. Your code is reading from the xml file.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: how to write xml in rss format from dataset
Jul 06, 2012 01:34 AM|LINK
Hi,
If you are running with aspx page,I'm afraid you cannot change that because the default page's name's suffix name is *.aspx;however you can use UrlWriter to rewrite the aspx page's index route like this:http://urlrewriter.net/index.php/download