草庐IT

removeAllAttributes

全部标签

xml - 在 C# 中从 XML 中删除所有属性的最简单方法是什么?

我想从XML中删除所有标签的属性(我只想保留标签及其内部值)。在C#中执行此操作的最简单方法是什么? 最佳答案 staticvoidremoveAllAttributes(XDocumentdoc){foreach(vardesindoc.Descendants())des.RemoveAttributes();}用法:vardoc=XDocument.Load(path);//Or.Parse("xml");removeAllAttributes(doc);stringres=doc.ToString();