假设有如下表

InfoMap(

Name varchar(50),

Address varchar(50),

Tel varchar(50),

location geometry)

则动态生成所需的GeoRss的Xml文件的代码如下:

Response.Expires = -1;
Response.ContentType = "text/xml";
Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");

using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection("Data  Source=YouDataSource;InitialCatalog=DatabaseName;Persist Security Info=True;User ID=sa;Password=password"))
using (System.Data.SqlClient.SqlCommand cmd = cn.CreateCommand())
{

cmd.CommandText = @"
WITH XMLNAMESPACES ( 'http://www.opengis.net/gml' as gml,'http://www.georss.org/georss' as georss,default 'http://www.w3.org/2005/Atom' )
select  title=name,
summary='地址:'+address+'</br>电话:'+Tel,
location.AsGml().value('(/*/*)[1]','nvarchar(max)')  as 'georss:where/gml:Point/gml:pos'
from InfoMap for xml path('entry'),ELEMENTS , ROOT('feed')
";
cn.Open();
System.Xml.XmlReader r = cmd.ExecuteXmlReader();
System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(Response.Output);

r.MoveToContent();
while (!r.EOF)
{

        w.WriteNode(r, true);
}
r.Close();
w.Flush();

}