【发布时间】:2015-03-31 03:53:42
【问题描述】:
我正在寻找使用 C# 为网站创建 rss 提要。我想要解决的是,一旦我点击了一个按钮(“添加提要”),它就会创建一个节点元素,如下所示:
<item>
<title> some title...here </title>
<link> link to the article ...here </link>
<description> article's description ...here </description>
</item>
这必须是
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Example Home Page</title>
<link>http://www.example.com</link>
<description>Educational Website...</description>
<image>
<url>http://www.example.com/images/logo.png</url>
<title>Example.com</title>
<link>http://www.example.com</link>
</image>
<category>Photography</category>
<language>en-us</language>
</channel>
<item>
<title> some title...here </title>
<link> link to the article ...here </link>
<description> article's description ...here </description>
</item>
</rss>
这是代码:
XmlDocument doc = new XmlDocument();
XmlNode item = doc.CreateElement("item");
XmlNode Title = doc.CreateElement("title");
Title.InnerText = TextBoxTitle.Text;
item.AppendChild(Title);
XmlNode link = doc.CreateElement("link");
link.InnerText = "http://www.example.com/" + DropDownListCategory.SelectedItem.Text + ".aspx?key=" + TextBoxLink.Text + ".txt";
item.AppendChild(link);
XmlNode description = doc.CreateElement("description");
description.InnerText = TextBoxDescription.Text;
item.AppendChild(description);
doc.DocumentElement.AppendChild(item);
doc.Save(Server.MapPath("~/rss.xml"));
我该怎么做?任何帮助或反馈将不胜感激。谢谢!!!
【问题讨论】: