我最近在開發.net 2.0項目,我必須閱讀一些xml文件並替換某些元素值。 想知道你如何做到這一點以下不使用LINQ到XML?將以下Linq轉換爲xml爲.net 2.0
IEnumerable<XElement> cities= xmldoc.Descendants("City")
.Where(x => x.Value == "London");
foreach (XElement myElem in cities)
{
myElem.ReplaceWith(new XElement("City", "NewCity"));
}
或
var xElement = xdoc.Descendants("FirstName").Where(x => x.Value == "Max").First();
xElement.ReplaceWith(new XElement("FirstName", "NewValue");
任何建議
閱讀此SO後 - LINQ上的.NET 2.0運行時間http://stackoverflow.com/questions/2138/linq-on-the-net-2-0-runtime – adatapost
看看這裏http:// www.developer.com/net/csharp/article.php/3489611 –