Posts recientes

El contenido de este blog tiene una licencia Creative Commons.
Creative Commons

Generación RSS con linq.   

Os dejo a mano un método para la generación de un RSS haciendo uso de las herramientas que facilita Linq para la generación de XML's trabajando contra un EntityModel.
using System;
using System.Xml;
using System.Xml.Linq;
using System.Linq;

public XDocument getXmlData()
{
   using (EntitiesDefinition ent = new EntitiesDefinition()) 
   {
   XDocument xml = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), 
      new XElement("rss", new XAttribute("version", "2.0"), 
      new XElement("channel", 
      new XElement("title", "TITULO"), 
      from tabla in ent.GetInfo() 
      orderby tabla.Fecha descending 
      select 
         new XElement("item", 
         new XElement("title", tabla.Campo1 + " " + tabla.Campo2), 
         new XElement("pubDate", tabla.Fecha), 
         new XElement("description", tabla.Descripcion) 
         ) 
      ))); 
      return xml; 
   } 
} 

Esta función devolvería un xml(formato RSS) que ya puede ser interpretado de forma correcta por los navegadores.

En caso de necesidad de más información sobre el formato RSS 2.0 o ver todos los tags disponibles, dejo aquí una página sobre la especificación de RSS 2.0

Espero os sirva de ayuda.

 

 
Publicado  en  27/08/2010  por  David Acosta Lesmes
0  Comentarios  |  Trackback Url  | 0  Enlaces a este post | Bookmark este post con:          
Etiquetas: ASP.NET, C#, VS 2010, Linq
Technorati Tags: , , ,
 

Vinculos a este post

Comentarios