To the best of my knowledge, using XmlDocument, there is no direct way to do this. You will need to do something like the following
- Get the value of the comment node
- Create a new XmlNode with the value from step 1
- Delete the comment node
- Add the new node from step 2 to the DOM tree
Here is an example with a slightly simplified version of your XML and addressing your quesion in the comments on finding the correct comment node. Note that I query for all comment nodes, obviously you can be more specific and query the portion of the document that you are interested in.
string xml = @"
<root>
<!--<reltable toc='no' class='- map/reltable '>
<relheader class='- map/relheader '>
<relcolspec type='concept' class='- map/relcolspec '/>
</relheader>
</reltable> -->
<!--<reltable toc='no' class='- map '>
<relheader class='- map/relheader '>
<relcolspec type='concept' class='- map/relcolspec '/>
</relheader>
</reltable> -->
</root>";
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xml);
XmlNodeList commentedNodes = xdoc.SelectNodes("//comment()");
var commentNode = (from comment in commentedNodes.Cast<XmlNode>()
where comment.Value.Contains("class='- map '")
select comment).FirstOrDefault();
if (commentNode != null)
{
XmlReader nodeReader = XmlReader.Create(new StringReader(commentNode.Value));
XmlNode newNode = xdoc.ReadNode(nodeReader);
commentNode.ParentNode.ReplaceChild(newNode, commentNode);
}
Chris Taylor
2010-09-09 13:41:54