我在下面有一个 xml 文件
<?xml version="1.0" encoding="utf-8"?><rss version="2.0">
<channel>
<title>About RSS</title>
<link>http://localhost:27549/TTTT.aspx</link>
<description>The latest news</description>
<image><url>http://localhost:27549/images/ttt_logo.jpg</url></image>
<item>
<title>ABC</title>
<link>http://localhost:27549/Viewttt.aspx?id=217</link>
<description>zzzzzzzzzzzzzzzzzzz...</description>
<pubDate>Tuesday, August 30, 2011, 00:00:00AM</pubDate>
</item>
</channel>
</rss>
虽然您可以看到 pubdate 标签,但它不会显示在 pubDate 位置。这是我获取 pubdate 的代码,但它不起作用,
DateTime dt = DateTime.ParseExact(pubDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
pubDate = dt.ToString("dddd, MMMM dd, yyyy, HH:mm:sstt");
writer.WriteElementString("pubDate", pubDate);
例如,我尝试获取今天的日期,如下所示,
writer.WriteElementString("pubDate", DateTime.Now.ToString("r"));
并且日期正在显示。第一组代码可能有什么问题?
String pubDate = "";
using (System.Data.Common.DbCommand dbCommand = DataAccess.Instance().Database.GetStoredProcCommand("usp_GetLatestNews"))
{
using (IDataReader reader = DataAccess.Instance().Database.ExecuteReader(dbCommand))
{
int i = 0;
while (reader.Read())
{
if (i == 0)
{
newsHeader = "New News Summary Available for " + reader["Title"].ToString() + " - " + reader["PubDate"];
newsLink = "ViewTTT.aspx?id=" + reader["Id"].ToString();
newsDesc = reader["FullDescription"].ToString();
pubDate = reader["pubDate"].ToString();
DateTime dt = DateTime.ParseExact(pubDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
pubDate = dt.ToString("r");
}
i++;
}
};
}
AddRSSItem(writer, newsHeader, newsUrl, newsDesc, pubDate);
.............
.............
public XmlTextWriter AddRSSItem(XmlTextWriter writer,
string sItemTitle, string sItemLink,
string sItemDescription, String pubDate)
{
writer.WriteStartElement("item");
writer.WriteElementString("title", sItemTitle);
writer.WriteElementString("link", sItemLink);
writer.WriteElementString("description", sItemDescription);
writer.WriteElementString("pubDate", pubDate);
writer.WriteEndElement();
return writer;
}