Firstly you should know that
XmlDocument
does't give you the position of the elements in source stream.
So you have to use
Html Agility Pack
:
http://htmlagilitypack.codeplex.com/wikipage?title=Examples[
^]
Then you will have something like this :
HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlDocument();
var content =@"<a>
<b />
<c />
</a>";
htmlDocument.LoadHtml(content);
var desiredNode = htmlDocument.DocumentNode.SelectNodes("/a/b")[0];
content = content.Insert(desiredNode.StreamPosition + desiredNode.OuterHtml.Length, "-->");
content = content.Insert(desiredNode.StreamPosition, "<!--");
Remember to add some error checkings.
Hope it helps.