读书人

为什么小弟我在xml里只能删属性的值

发布时间: 2012-04-13 13:50:24 作者: rapoo

求教:为什么我在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"]);

读书人网 >asp.net

热点推荐