在ASP.NET 3.5中创建RSS源
如何使用C#在ASP.NET 3.5中创建RSS源?
哪些框架部分有助于.NET开发人员更轻松地发布RSS或Atom提要?
.NET 4中是否有任何额外的function使这项任务比3.5更容易?
在3.5中有一个名为System.ServiceModel.Syndication的新命名空间。
Kevin Miller 对此有一个很好的写作 ,对于新的命名空间来说并不是很多,查看文章,不需要在这里重新发布,在我看来,示例代码更容易看。
上述就是C#学习教程:在ASP.NET 3.5中创建RSS源分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
public void BindData() { StringWriter sw = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(sw); XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); writer.WriteStartElement("feed"); writer.WriteAttributeString("xmlns", "https://www.w3.org/2005/Atom"); writer.WriteString("n"); writer.WriteElementString("title", this.TTT + " - " + this.Title); writer.WriteString("n"); writer.WriteStartElement("link"); writer.WriteAttributeString("href", this.Url ); writer.WriteEndElement(); writer.WriteElementString("id", "urn:uuid:" + Guid.NewGuid().ToString()); writer.WriteElementString("updated", DateTime.UtcNow.ToString("o")); foreach (var item in this.lista) { writer.WriteStartElement("entry"); writer.WriteElementString("title", item.Value.Title); writer.WriteStartElement("link"); writer.WriteAttributeString("href", item.Key); writer.WriteEndElement(); writer.WriteElementString("id", item.Key); string slikaImgUrl = item.Value.Imaga; if (string.IsNullOrEmpty(slikaImgUrl) == false) { writer.WriteStartElement("link"); writer.WriteAttributeString("rel", "enclosure"); writer.WriteAttributeString("type", "image/jpeg"); writer.WriteAttributeString("href", slikaImgUrl); writer.WriteEndElement(); } writer.WriteStartElement("author"); writer.WriteElementString("name", this.Title); writer.WriteEndElement(); writer.WriteStartElement("summary"); writer.WriteAttributeString("type", "text"); writer.WriteCData(" "); writer.WriteEndElement(); writer.WriteElementString("updated", DateTime.UtcNow.ToString("o")); writer.WriteElementString("published", DateTime.UtcNow.ToString("o")); writer.WriteEndElement(); writer.WriteString("n"); } writer.WriteEndElement(); string dataOut = sw.ToString(); Response.Clear(); Response.ContentType = "text/xml"; Response.Write(dataOut); writer.Close(); Response.End(); }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/990569.html