我知道它的很多代碼...對不起那個....我的列表類是這樣的..列表裏面名單
public class XMLList
{
public string Title { get; set; }
[DataMember]
public string Link { get; set; }
[DataMember]
public DateTime pubDate { get; set; }
[DataMember]
public string dcCreator { get; set; }
[DataMember]
public string GUID { get; set; }
[DataMember]
public Int32 wpPostId { get; set; }
[DataMember]
public string wpStatus { get; set; }
[DataMember]
public Int32 wpMenuOrd { get; set; }
[DataMember]
public string Category { get; set; }
[DataMember]
public List<Comment> Comments { get; set; }
}
public class Comment
{
[DataMember]
public Int32 wpCmtId { get; set; }
[DataMember]
public string wpCmtAuthor { get; set; }
[DataMember]
public string wpCmtAuthorEmail { get; set; }
[DataMember]
public string wpCmtAuthorURL { get; set; }
[DataMember]
public Int64 wpCmtAuthorIP { get; set; }
[DataMember]
public DateTime wpCmtAuthorDate { get; set; }
}
我的C#代碼是這樣的
XmlDocument doc = new XmlDocument();
doc.Load(@"xml\willowcreekassociationblog.wordpress.xml");
//Get Channel Node
XmlNode channelNode = doc.SelectSingleNode("rss/channel");
if (channelNode != null)
{
//Add NameSpace
XmlNamespaceManager nameSpace = new XmlNamespaceManager(doc.NameTable);
nameSpace.AddNamespace("excerpt", "http://wordpress.org/export/1.2/excerpt/");
nameSpace.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/");
nameSpace.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
nameSpace.AddNamespace("wfw", "http://wellformedweb.org/CommentAPI/");
nameSpace.AddNamespace("wp", "http://wordpress.org/export/1.2/");
//Parse each item
foreach (XmlNode itemNode in channelNode.SelectNodes("item"))
{
objrssItem.Add(rssItem);
rssItem.GUID = itemNode.SelectSingleNode("guid").InnerText;
rssItem.Title = itemNode.SelectSingleNode("title").InnerText;
rssItem.dcCreator = itemNode.SelectSingleNode("dc:creator", nameSpace).InnerText;
rssItem.Link = itemNode.SelectSingleNode("link").InnerText;
rssItem.pubDate = DateTime.Parse(itemNode.SelectSingleNode("pubDate").InnerText);
rssItem.ContentEncoded = itemNode.SelectSingleNode("content:encoded", nameSpace).InnerText;
XmlNode cNode = doc.SelectSingleNode("rss/channel/item");
foreach (XmlNode commentNode in cNode.SelectNodes("wp:comment", nameSpace))
{
//rssItem.Comments = Comments
rsscomment.wpCmtId = Convert.ToInt32(commentNode.SelectSingleNode("wp:comment_id", nameSpace).InnerText);
rsscomment.wpCmtAuthor = commentNode.SelectSingleNode("wp:comment_author", nameSpace).InnerText;
rsscomment.wpCmtContent = commentNode.SelectSingleNode("wp:comment_content", nameSpace).InnerText;
}
}
oXMLListResult.listOfXMLResult = objrssItem;
}
我有xml像enter link description here
當我試圖讀取通道中的每個項目與xmlnode和它的工作正常。並且每個項目都有多個註釋,試圖通過在foreach中使用foreach來實現。但WP:評論foreach項目不起作用。我究竟做錯了什麼?我做了一些谷歌,但沒有運氣。
謝謝。
這個問題讓我想起那些連鎖電子郵件笑話,你必須向下滾動幾頁才能看到妙語。你能刪除一些空白嗎? – 2012-07-26 15:35:28
空白區域是圖像文件。 – Philly 2012-07-26 15:44:16
那麼也許你應該裁剪圖像文件:P – 2012-07-26 15:44:55