7
我試圖用不同的XML從另一個文件
見下面的代碼創建一個xmldocument
對象創建的XmlDocument
編輯1 Compleate的代碼塊:
try
{
XmlDocument objNewsDoc = new XmlDocument();
string strNewsXml = getNewsXml();
objNewsDoc.LoadXml(strNewsXml);
var nodeNewsList = objNewsDoc.SelectNodes("news/newsListItem");
XmlElement news = docRss.CreateElement("news");
foreach (XmlNode objNewsNode in nodeNewsList)
{
string newshref = objNewsNode.Attributes["href"].Value;
string strNewsDetail = getNewsDetailXml(newshref);
try
{
objNewsDoc.LoadXml(strNewsDetail);
XmlNode importNewsItem = docRss.ImportNode(objNewsDoc.SelectSingleNode("newsItem"), true);
news.AppendChild(importNewsItem);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
docRss.Save(Response.Output);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
+1的工作。但我仍然得到docrss爲空當我使用'docRss.Save(Response.Output);'輸出完成文檔 – Champ
我已添加完整的代碼塊,你可以幫助嗎? – Champ
你太親近了!問題是你已經創建了你想要的所有xml,但是你沒有將新聞元素添加到你的輸出文檔中。看到我更新的答案。 – dash