|
hola a tod@s!! estoy creando una aplicación web para un periódico digital. Me gustaría hacer que se pudiesen sindicar las noticias, con xml. Pero, la verdad que no tengo muy claro como hacerlo. En principio he hecho lo siguiente:
/*escribir el ppio del archibo xml*/ public XmlTextWriter escribirInicioRSS(System.Xml.XmlTextWriter writer) { writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version","2.0"); writer.WriteStartElement("channel"); writer.WriteElementString("title","titulo"); writer.WriteElementString("link","link"); writer.WriteElementString("description","descripcion"); writer.WriteElementString("languaje","es-es"); writer.WriteElementString("generator","Creador de RSS por Elena"); return writer; }
/*para añadir cada uno de los elementos al archivo*/ public XmlTextWriter agregarItemRSS(XmlTextWriter writer,string sTitulo,string stexto,string sFechapub,string sAutor,int idarticulo) { writer.WriteStartElement("item"); writer.WriteElementString("title",sTitulo); writer.WriteElementString("description",stexto); writer.WriteElementString("pubDate",sFechapub); writer.WriteElementString("author",sAutor); string cadena="http://localhost/interfaz/Artículo.aspx?idarticulo=" +idarticulo.ToString(); writer.WriteElementString("link",cadena); writer.WriteEndElement(); return writer; }
/*para cerrar el documento xml*/ public System.Xml.XmlTextWriter escribirFinalRSS() { writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); return writer; }
Bien, en el documento de origen (donde está el botoncito naranja de XML) se recogen los datos de cada uno de los artículos y se llama a la funcion añadirItemRSS. El objeto writer está así definido:
XmlTextWriter writer= new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);
Y, una vez que se han agregado todos los item y se ha llamado a la función escribirFinalRSS, añado lo siguiente:
writer.Flush(); writer.Close(); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; Response.Cache.SetCacheability(HttpCacheability.Public); Response.End();
Sin embargo, cuando intento añadir la dirección de mi feed a un lector...me pide una contraseña y username, x lo que deduzco que hago algo mal alguien m puede ayudar??? (ejem...ya sé...el código no está ni en c ni en c++....es c#...pero si m pueden ayudar lo agradecería) gracias. un saludo
|