Scrivere Feed RSS

mercoledì 01 febbraio 2006 - 17.53

DesartStudio Profilo | Newbie

Salve vorrei scrivere un feed RSS, conoscete un metodo "veloce" per poter creare una struttura XML compatibile RSS 2.0?
e/o altre info interessanti per raggiungere questo scopo?!

GRazie

Antonio

ps: lo realizzerei in .net 2.0

freeteo Profilo | Guru

ciao,
puoi usare qualche assembly gia fatto come:
http://sourceforge.net/projects/rss-net/
...etc...che trovi cercando su google...

o fartelo a mano, strutturando correttamente 1documento xml in response nel load della pagina:
...
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version","2.0");
objX.WriteStartElement("channel");
objX.WriteElementString("title", "...");
objX.WriteElementString("link","...");
objX.WriteElementString("description","...");
objX.WriteElementString("copyright","...");
objX.WriteElementString("ttl","5");

...coinnessione al db con reader....

while (objReader.Read())
{
objX.WriteStartElement("item");
objX.WriteElementString("title",objReader.GetString(0));
objX.WriteElementString("description",objReader.GetString(1));
objX.WriteElementString("link"...
objX.WriteElementString("author", objReader.GetString(4));
objX.WriteElementString("pubDate", objReader.GetDateTime(3).ToString("R"));
objX.WriteEndElement();
}
...chiudi tutto...e finisci

objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
Response.End();

io propendo per la 2a inquanto riesco a farmi quello che volgio cmq...ma sai a volte trovarlo gia fatto si fa molto prima ;-)

Matteo Raumer
MCAD.net - net addicted :-)
http://blogs.dotnethell.it/freeteo

DesartStudio Profilo | Newbie

ciao grazie prima di tutto :)
si infatti avevo iniziato a crearmelo a mano in questo modo

Dim xDoc As New Xml.XmlDocument()
Dim RSSNode As Xml.XmlNode = xDoc.CreateNode(Xml.XmlNodeType.Element, "rss", "")
Dim RSSNodeAttribute1 As Xml.XmlAttribute = xDoc.CreateAttribute("version")
RSSNodeAttribute1.Value = "2.0"
Dim RSSNodeAttribute2 As Xml.XmlAttribute = xDoc.CreateAttribute("xmlns:dc")
RSSNodeAttribute2.Value = "http://purl.org/dc/elements/1.1/"
RSSNode.Attributes.Append(RSSNodeAttribute2)
RSSNode.Attributes.Append(RSSNodeAttribute1)
xDoc.AppendChild(RSSNode)
Dim xNode As Xml.XmlNode = xDoc.CreateNode(Xml.XmlNodeType.Element, "channel", "")
......ecc ecc
può andare una cosa del genere?
un'altra cosa che ti chiedo gentilmente è "xmlns:dc" che attributo rappresenta??...ho riportato nel codice un link che avevo letto in un esempio e vedo che spesso esso non è neanch epresente.

GRazie
Antonio F.

DesartStudio Profilo | Newbie

scusami per la mia ignoranza vedo che cominci con un reponse..
potresti dirmi da cosa proviene quel response?

Grazie

ps: il link è inattivo di rss.net :)

DesartStudio Profilo | Newbie

humm ....per il response tu interagivi con l'html credo..
cmq per chi può fare comodo l'ho traslato in vb.net così
...accetta un dataset che poi ne cicla la prima tabella..

Dim objX As Xml.XmlTextWriter
objX.WriteStartDocument()
objX.WriteStartElement("rss")
objX.WriteAttributeString("version", "2.0")
objX.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/")
objX.WriteStartElement("channel")
objX.WriteElementString("title", "...")
objX.WriteElementString("link", "...")
objX.WriteElementString("description", "...")
objX.WriteElementString("copyright", "...")
objX.WriteElementString("ttl", "5")
Dim dsx As New DataSet
Dim dr As DataRow
Dim i As Integer = 0
For Each dr In dsx.Tables(0).Rows
objX.WriteStartElement("item")
objX.WriteElementString("title", ds.Tables(0).Rows(i)(1).ToString)
objX.WriteElementString("description", ds.Tables(0).Rows(i)(2).ToString)
objX.WriteElementString("link", ds.Tables(0).Rows(i)(3).ToString)
objX.WriteElementString("author", ds.Tables(0).Rows(i)(4).ToString)
objX.WriteElementString("pubDate", ds.Tables(0).Rows(i)(5).ToString)
objX.WriteEndElement()
i += 1
Next
objX.WriteEndElement()
objX.WriteEndElement()
objX.WriteEndDocument()
objX.Flush()
objX.Close()

mexico77 Profilo | Junior Member

scusatemi ma sarei interessanto alla cosa, solo che sono alle prima ìarmi con dot.net!
Mi da un errore sulla riga: Dim objX As Xml.XmlTextWriter dicendo che non è un tipo definito.
Ho anche importato questo namespace ma senza risultati.

Poi un'ultima cosa il dataset come lo creo? E imposto i campi da prendere?

Grazie a tutti

www.themex.it
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5