首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

为什么小弟我在xml里只能删属性的值,删不了属性名?

2012-04-13 
求教:为什么我在xml里只能删属性的值,删不了属性名??XmlDocument doc new XmlDocument()doc.Load(openF

求教:为什么我在xml里只能删属性的值,删不了属性名??
XmlDocument doc = new XmlDocument();
  doc.Load(openFileDialog1.FileName);

  XmlElement root = doc.DocumentElement;

  root.LastChild.Attributes["id"].RemoveAll();
-------------------------
结果就把 id="234" 变成了 id=""
怎么样能都删掉???

[解决办法]
root.LastChild.Attributes.RemoveNamedItem("id");

doc.Save(openFileDialog1.FileName)

或者

root.LastChild.Attributes.Remove(root.LastChild.Attributes["id"]);

热点排行