Foros del Web » Programación para mayores de 30 ;) » .NET »

Ayuda Con Rss - Asp.net C#

Estas en el tema de Ayuda Con Rss - Asp.net C# en el foro de .NET en Foros del Web. Buenas a todos y gracias por leer mi post, bueno tengo una duda sobre XML (RSS)+ asp.net C# Estoy tratando de consumir un RSS y ...
  #1 (permalink)  
Antiguo 04/02/2008, 14:13
 
Fecha de Ingreso: septiembre-2005
Mensajes: 34
Antigüedad: 18 años, 7 meses
Puntos: 0
Ayuda Con Rss - Asp.net C#

Buenas a todos y gracias por leer mi post, bueno tengo una duda sobre XML (RSS)+ asp.net C#

Estoy tratando de consumir un RSS y encontre hasta 3 formas distintas pero ninguna me resuelve el problema:

EL problema: ¿Como leo RSS con RDF?

Me explico...

Los 3 metodos funcionan para leer RSS simples tipo los de Blogs: xejemplo.-> http://www.telurica.com/feed/canal/humor

Pero para un RSS con tags como: <item rdf:about ......> xejemplo-> http://feeds.feedburner.com/el-comercio-minuto-a-minuto?format=xml , o para la de CNN...no funcionan...y me parece q es por tipo de tags...


Los Metodos:

1)
Traté usando:
--Desde Diseño jale un GridView (Datagrid1)
--desde codigo cs:

XmlTextReader lec = new XmlTextReader("http://www.telurica.com/feed/canal/humor");
DataSet ds = new DataSet();
ds.ReadXml(lec);
GridView1.DataSource = ds.Tables[2];
GridView1.DataBind();

*Esto funciona bien con rss 2.0 (aunque muestra todos los datos de tags y solo me gustaria jalar los tags de <title>,<link>,<description>), pero para rss normales como la de paginas de periodicos me da el sigt error:

A column named 'link' already belongs to this DataTable: cannot set a nested table name to the same name.

existe alguna manera de cambiar los campos del GridView asi como Decirle que solo me muestre los datos de los tags que yo deseo ??

2)
El segundo metodo q vi era usando XML y XSL

Con el xsl tratar de extraer solo los campos que quiero pero al igual que el metodo anterior funciona de maravilla para RSS 2.0 de blogs, pero con los rss de periodicos simplemente no me muestra nada (solo la cabecera de tablas html) ...

ok.xsl
====
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<td>
<b>Titulo</b>
</td>
<td>
<b>Descripcion</b>
</td>
</tr>

<!--creo q aca esta el error. sq en los rss de periodicos el tag item es <item rdf:about ......> y por eso el Xpath no lo encuentra... -->

<xsl:for-each select=".//item" >
<tr>
<td>
<xsl:element name="a">
<xsl:attribute
name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
</td>
<td>
<xsl:value-of select="description"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

RSS.cs
=====
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {

if (!Page.IsPostBack) {
// mostrar el rss solo en la primera peticion
//MostrarRSS();
}
}
void btnCargarRSS_Click(object sender, EventArgs e) {
MostrarRSS();
}
private void MostrarRSS()
{
String rssURL="http://www.telurica.com/feed/canal/humor";
System.Xml.XmlTextReader lector = new System.Xml.XmlTextReader(rssURL);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(lector);
xmlRSS.Document = doc;
String xslsrc = "ok.xsl";
xmlRSS.TransformSource = xslsrc;
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Button id="btnCargarRSS" onclick="btnCargarRSS_Click" runat="server" Text="Cargar RSS"></asp:Button>
</p>
</form>
<p>
<asp:xml id="xmlRSS" runat="server"></asp:xml>
</p>
</body>
</html>

3)
El tercer metodo lo encontre en una pg algo antigua y funciona pero con el mismo resultado de los 2 anteriores:

codigo cs
======

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Noticias.aspx.cs" Inherits="Default10" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script runat="server">
public void ProcessRSSItem(string rssURL)
{
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();
rssDoc.Load(rssStream);
//Al igual q el ejemplo anterior creo q la falla esta aca ya que item en el rss de periodicos tiene otra estrucura
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");
string title = "";
string link = "";
string description = "";
for (int i = 0; i < rssItems.Count; i++)
{
System.Xml.XmlNode rssDetail;
rssDetail = rssItems.Item(i).SelectSingleNode("title");
if (rssDetail != null)
{
title = rssDetail.InnerText;
}
else
{
title = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("link");
if (rssDetail != null)
{
link = rssDetail.InnerText;
}
else
{
link = "";
}
rssDetail = rssItems.Item(i).SelectSingleNode("description");
if (rssDetail != null)
{
description = rssDetail.InnerText;
}
else
{
description = "";
}
Response.Write("<p><b><a href='" + link + "' target='new'>" + title + "</a></b><br/>");
Response.Write(description + "</p>");
}
}
</script>
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<%
string rssURL = "http://feeds.feedburner.com/el-comercio-minuto-a-minuto?format=xml";
Response.Write("<font size=5><b>Site: " + rssURL + "</b></font><Br />");
ProcessRSSItem(rssURL);
Response.Write("<hr />");
rssURL = "http://www.larepublica.com.pe/component/option,com_rss/feed,RSS1.0/no_html,1/Itemid,578/";
Response.Write("<font size=5><b>Site: " + rssURL + "</b></font><Br />");
ProcessRSSItem(rssURL);
%>
</div>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
</asp:Content>

Bueno...eso es hasta donde llegue por el momento...talvez alguien ya investigo esto y me pueda ayudar....

Espero me haya explicado bien y alguien me pueda ayudar....

MUCHAS GRACIAS

salu2.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:12.