使用 C# 取消注释 XML 文件中的注释节点
我有一个 XML 文件,其中有一个被注释掉的节点。我使用以下语法创建了此节点:
relTableCommentedNode = xDoc.CreateNode(XmlNodeType.Comment, "RELTABLECOMMENTED", "np");
取消注释此节点的最佳方法是什么?我可以根据用于创建节点的名称 (RELTABLECOMMENTED
) 来识别该节点吗?
这是评论的节点:
<code>
<pre>
<!--<reltable toc="no" class="- map/reltable ">
<relheader class="- map/relheader ">
<relcolspec type="concept" class="- map/relcolspec ">
</relheader>
<relrow class="- map/relrow ">
<relcell class="- map/relcell ">
<topicref href="concepts\about_cannedgoods.dita" copy-to="concepts\about_cannedgoods.dita" class="- map/topicref " xmlns:dctm="http://www.documentum.com">
</topicref>
</relcell>
</relrow>
</reltable> -->
</pre>
</code>
I have a XML file which has a node which is commented out. I have created this node using the syntax:
relTableCommentedNode = xDoc.CreateNode(XmlNodeType.Comment, "RELTABLECOMMENTED", "np");
What is the best approach to uncomment this node? Can I identify this node based on the name which I used to create the node (RELTABLECOMMENTED
)?
This the commented node:
<code>
<pre>
<!--<reltable toc="no" class="- map/reltable ">
<relheader class="- map/relheader ">
<relcolspec type="concept" class="- map/relcolspec ">
</relheader>
<relrow class="- map/relrow ">
<relcell class="- map/relcell ">
<topicref href="concepts\about_cannedgoods.dita" copy-to="concepts\about_cannedgoods.dita" class="- map/topicref " xmlns:dctm="http://www.documentum.com">
</topicref>
</relcell>
</relrow>
</reltable> -->
</pre>
</code>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,使用 XmlDocument 没有直接的方法来做到这一点。您将需要执行如下操作
这是一个稍微简化版本的示例您的 XML 并解决您在评论中找到正确评论节点的问题。请注意,我查询了所有注释节点,显然您可以更具体地查询您感兴趣的文档部分。
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
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.