<Snippets> <Snippet name="abc"> <SnippetCode> code goes here </SnippetCode> </Snippet> <Snippet name="def"> <SnippetCode> code goes here </SnippetCode> </Snippet></Snippets>解决方法 你可以尝试这样的东西:
string xmlinput = @"<Snippets> <Snippet name=""abc""> <SnippetCode> code goes here </SnippetCode> </Snippet> <Snippet name=""def""> <SnippetCode> code goes here </SnippetCode> </Snippet></Snippets>";// create the XML,load the contentsXmldocument doc = new Xmldocument();doc.LoadXml(xmlinput);// find a node - here the one with name='abc'XmlNode node = doc.SelectSingleNode("/Snippets/Snippet[@name='abc']");// if found....if (node != null){ // get its parent node XmlNode parent = node.parentNode; // remove the child node parent.RemoveChild(node); // verify the new XML structure string newXML = doc.OuterXml; // save to file or whatever.... doc.Save(@"C:\temp\new.xml");}总结
以上是内存溢出为你收集整理的c# – 如何从文件中删除一个xml元素?全部内容,希望文章能够帮你解决c# – 如何从文件中删除一个xml元素?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)