GeoRSS from C#

I wrote a little web page that creates an ATOM feed to return records as they were read from a database. I have my reasons why I published my data as GeoRSS rather than a standard XML feed so we’ll leave it at that. Let’s just say that most of the ESRI Flex applications I’ve worked with do a pretty good job of handling GeoRSS data and you get 2 for 1 because your users can also view the data in their favorite RSS Reader! Here is my code…It doesn’t get much easier than this but if you do have a better way to publish an ATOM feed, I’d love to see it because I really don’t know how to do it!

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public void ProcessRequest(HttpContext context)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[MyConnectionString"].ConnectionString);
 
            conn.Open();
 
            SqlDataReader rss = null;
            SqlCommand rss_cmd = new SqlCommand("SELECT TOP 100 FROM MyDB ORDER BY Updated DESC", conn);
            rss = rss_cmd.ExecuteReader();
 
            Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
            Response.Write("<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:georss=\"http://www.georss.org/georss\">\n");
            Response.Write("<title>Site Name</title>\n");
            Response.Write("<link href=\"http://www.yoururl.com\" />\n");
            Response.Write("<updated>" + DateTime.Now.ToString() + "</updated>\n");
            Response.Write("<author>\n");
            Response.Write("<name>Adam con Carne</name>\n");
            Response.Write("<url>href=\"http://www.yoururl.com"</url>\n");
            Response.Write("</author>\n");
            Response.Write("<id>urn:uuid:" + System.Guid.NewGuid() + "</id>\n");
 
            string title = string.Empty;
            while (Name.Read())
            {
                title = dr["Title"].ToString();
                title = title.Replace("&", "&amp;");
                title = title.Replace("\\", "&quot;");
                title = title.Replace("<", "&lt;");
                title = title.Replace(">", "&gt;");
 
                Response.Write("<entry>\n");
                Response.Write("<title>" + title + "</title>\n");
                Response.Write("<link href=\"default.aspx?article=" + dr["ID"].ToString() + "\"/>\n");
                Response.Write("<id>urn:uuid:" + System.Guid.NewGuid() + "</id>\n");
                Response.Write("<summary>Asset ID: " + dr["Asset_ID"].ToString() + "</summary>\n");
                Response.Write("<updated>" + dr["Updated"].ToString() + "</updated>\n");         
                Response.Write("<georss:point>" + dr["Latitude"].ToString() + " " + dr["Longitude"].ToString() + "</georss:point>\n");
                Response.Write("</entry>\n");
            }
 
            Response.Write("</feed>");
 
            Response.ContentType = "application/ATOM+XML";
            Response.AppendHeader("Content-Encoding", "ATOM");
            Response.Clear();
            conn.Close();
        }

Again, the GeoRSS-ATOM formatted feed that is produced here can be used several different ways which means that less really *is* more! I will post more on this in future posts…

Bookmark and Share
This entry was posted in Design, GeoSpatial and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free