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!
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("&", "&"); title = title.Replace("\\", """); title = title.Replace("<", "<"); title = title.Replace(">", ">"); 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…
More from Adam Estrada
- How to copy music from your iPod to your iPhone
- Open Street Map (take 1)
- Customizing config.xml in the ESRI FlexViewer
- SpatiaLite 2.4.0
- jQuery Cascading Dropdown Menus
Adam Estrada Recommends
- Adam - The Indian iPad killer (MtaraM)
- Update from Google Map on my Problem (Maploser)
- Layar for the iPhone (Maploser)