Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/03/2007, 12:12
Avatar de 3pies
3pies
Colaborador
 
Fecha de Ingreso: diciembre-2003
Ubicación: Desde una destilería
Mensajes: 2.584
Antigüedad: 20 años, 6 meses
Puntos: 144
Re: Crear rss desde ASP

Ejemplo de código para un fichero que llamaremos noticias.asp
Código:
<%
'Creamos la conexión con la Base de Datos
set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("noticias.mdb"))
'Montamos la sentencia SQL, con las 5 cinco noticias
SQL="SELECT TOP 5 id, fecha, titulo, noticia, autor FROM noticias ORDER BY fecha DESC"
'Ejecutamos la consulta
set rs=oConn.Execute(SQL)
'Escribimos el código xml
response.write "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"
response.write "<rss version=""2.0"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:content=""http://purl.org/rss/1.0/modules/content/"">"
response.write "<channel>"
response.write "<title>Noticias de mi web</title>"
response.write "<link>http://www.tuweb.com</link>"
response.write "<description>Mi web, y tal y tal...</description>"
response.write "<language>es-ES</language>"
'Vamos al primer registro
rs.MoveFirst
'Montamos el bucle
do while not rs.eof
 autor=rs("autor")
 response.write "<item>"
 'Mostramos los primeros 200 caracteres de la noticia
 if len(rs("noticia"))>200 then
  noticia=replace(left(rs("noticia"),200) & "...",vbCrLf,"<br />")
 else
  noticia=replace(rs("noticia"),vbCrLf,"<br />")
 end if
 'escribimos el nodo XML
 response.write "<title>" & rs("titulo") & "</title>"
 response.write "<link>http://www.tuweb.com/noticia.asp?id=" & rs("id") & "</link>"
 response.write "<description><![CDATA[" & noticia & "]]></description>"
 response.write "<guid>http://www.tuweb.com/noticia.asp?id=" & rs("id") & "</guid>"
 response.write "<dc:creator>" & autor & "</dc:creator>"
 response.write "</item>"
 'nos movemos al siguiente registro
 rs.MoveNext
loop
response.write "</channel>"
response.write "</rss>"
'Cerramos y limpiamos los objetos
rs.Close
oConn.Close
set rs=nothing
set oConn=nothing
%>
Si quisieras poner la fecha al lado de cada item, habría que pasarla a formato RFC-822.

Salu2