我希望在將它發送給客戶端之前從XElement中刪除所有的XComment。如何從XElement中刪除XComments?
從某種原因,它不能正常工作和removeMe.Count()= 0
有什麼想法?
{
// ...
myXml = XElement.Load(myPath);
var removeMe=myXml.Descendants().Where(x => x.NodeType == XmlNodeType.Comment);
removeMe.Count(); // this is 0 , (not what i was expected)
removeMe.Remove();
//...
string myResponseStr = myXml.ToString(SaveOptions.None);
context.Response.ContentType = "text/plain";
context.Response.Write(myResponseStr);
}
XML文件可不會停像
<user>
<name> Elen </name>
<userSettings>
<color> blue </color> <!-- the theme color of the page -->
<layout> horizontal </layout> <!-- layout choise -->
<!-- more settings -->
</userSettings>
</user>
謝謝。像魅力一樣工作... –