如何评论一个XMLElement使用C#? [英] How to comment an XMLElement using C#?
本文介绍了如何评论一个XMLElement使用C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序读取一个XML文件,我写的,每次当我执行的应用价值。
My application reads values from an xml file which I write everytime when I execute the application.
这是我做的我行注释:
XmlComment DirCom = doc.CreateComment("Comment")
XmlElementName.AppendChild(DirCom);
和它工作正常,但现在我需要评论的XML元素,上面没有工作。我最后的结果应该是这样的:
And It works fine, But now I need to comment the XML element, And the above doesn't work. My final result should be like:
<!--<name>David</name>-->
使用C#和XML文档库。
using C# and the XML document library.
推荐答案
要评论一个XML节点我会做这样的:
To comment an xml node I would do it like this :
XmlComment DirCom = doc.CreateComment(XmlElementName.OuterXml);
doc.InsertAfter(DirCom, XmlElementName);
doc.RemoveChild(XmlElementName)
这篇关于如何评论一个XMLElement使用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文