2008年11月22日土曜日

LINQ to XML でノード削除する。


public void Delete(string id) {
var fileName = Request.MapPath(DATA_FILE_PATH);

var xml = XDocument.Load(fileName);
var result = from item in xml.Descendants("item")
where (string)item.Element("id") == id
select item;

foreach(var item in result.ToList()) item.Remove();

xml.Save(fileName);
}

0 件のコメント: