I have been immersed in RSS for the past few days. I tried to use Asp.net to make an RSS feedxml file. I also learned it for a long time, but I only saw the RSS specification, haha, I feel like using the RSS scanner to view RSS is like using Outlook Express to access newsgroups. Below is an Asp.net page XML that I wrote with VB.net. aspx, including generating RSS. XML file
<% @ Import namespace = "system. xml" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. sqlclient" %>
<Script language = "VB" runat = "server">
Public sub page_load (SRC as object, e as eventargs)
Dim xmldoc as string = server. mappath ("RSS. xml"
Dim writer as xmltextwriter
dim sqlstring as string
dim myconnection as sqlconnection
dim mycommand as sqlcommand
dim mydatareader as sqldatareader
dim myconn as string = system. configuration. configurationsettings. appset_id ("conn"
dim I _id as string
dim I _title as string
dim I _content as string
dim I _day as string
sqlstring = "select top 10 ID, I _title, I _content, I _day from information order by ID DESC "
myconnection = new sqlconnection (myconn)
mycommand = new sqlcommand (sqlstring, myconnection)
myconnection. open ()
mydatareader = mycommand. executereader ()
try
writer = new xmltextwriter (xmldoc, encoding. utf8)
writer. formatting = formatting. indented
writer. writestartdocument (true)
writer. writecomment ("comment"
writer. writestartelement ("RSS"
writer. writeattributestring ("version", "0.92"
writer. writestartelement ("channel"
writer. writestartelement ("title"
writer. writestring ("channel name"
writer. writeendelement ()
writer. writestartele Ment ("Link"
writer. writestring ("http: // your url/"
writer. writeendelement ()
writer. writestartelement ("Description"
writer. writestring ("the latest 10 messages! "
writer. writeendelement ()
writer. writestartelement ("language"
writer. writestring ("ZH-CN"
writer. writeendelement ()
''' loop start
while mydatareader. read ()
I _id = mydatareader. getint32 (0 ). tostring ()
I _title = mydatareader. getstring (1 ). trim ()
I _content = mydatareader. getstring (2 ). trim ()
I _day = mydatareader. getdatetime (3 ). tostring ()
Writer. writestartelement ("item"
Writer. writestartelement ("title"
Writer. writestring (I _title)
Writer. writeendelement ()
Writer. writestartelement ("Description"
Writer. writecdata (left (I _content, 100 ))
Writer. writeendelement ()
Writer. writestartelement ("pubdate"
Writer. writestring (I _day)
Writer. writeendelement ()
Writer. writestartelement ("Link"
Writer. writestring ("http: // your url/jnszf. aspx? Id = "& I _id)
Writer. writeendelement ()
Writer. writeendelement ()
End while
'''' The loop ends.
Writer. writeendelement ()
Writer. writeendelement ()
Writer. Flush ()
Writer. Close ()
Dim doc as xmldocument = new xmldocument ()
Doc. Load (xmldoc)
Response. contenttype = "text/XML"
Doc. Save (response. Output)
Catch exp as exception
Response. Write (exp. tostring ())
Finally
If (not writer is nothing) then
Writer. Close ()
End if
End try
Mydatareader. Close ()
Myconnection. Close ()
End sub
</SCRIPT>
The same effect is shown on the RSS. ASPX page.
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. sqlclient" %>
<Script language = "VB" runat = "server">
Sub page_load (sender as object, e as eventargs)
Dim myconnection as sqlconnection
Dim myadapter as sqldataadapter
Dim sqlstring as string
Dim mydataset as Dataset
Dim myconn as string = system. configuration. configurationsettings. deleettings ("conn"
Myconnection = new sqlconnection (myconn)
Sqlstring = "select top 10 * from information order by id desc"
Myadapter = new sqldataadapter (sqlstring, myconnection)
Mydataset = new dataset
Myadapter. Fill (mydataset, "information ")
Response. contenttype = "text/XML"
Myrepeater. datasource = mydataset
Myrepeater. databind ()
End sub
</SCRIPT>
<? XML version = "1.0" encoding = "gb2312"?>
& Lt; RSS version = "0.92" & gt;
<Channel>
<Title> channel name </title>
<Link> http: // your url/</link>
<Description> the latest 10 records </description>
<Language> ZH-CN </language>
<Asp: repeater id = "myrepeater" runat = "server">
<Itemtemplate>
<Item>
<Title> <% # databinder. eval (container. dataitem, "I _title" %> </title>
<Description> <! [CDATA [<% # databinder. eval (container. dataitem, "I _title" %>]> </description>
<Pubdate> <% # databinder. eval (container. dataitem, "I _day" %> </pubdate>
<Link> http: // your url/jnszf. aspx? Id = <% # databinder. eval (container. dataitem, "ID" %> </link>
</Item>
</Itemtemplate>
</ASP: repeater>
</Channel>
</RSS>
these two pages are my experiences in one day. This Article is only used for data backup, I hope it will be helpful to you, and don't forget to configure the web. config. The database uses sqlserver 2000