如何注释一个xml节点 [英] how to comment an xml node

查看:102
本文介绍了如何注释一个xml节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个XML文件,如下所示

 <   a  > ; 
  <   b    > 
  <   c    > 
<  /a  >  


现在我想按如下方式更改xml

 <   a  > ; 
 <!-  < b/>  ->  
 <   c    > 
<  /a  >  


我该如何移动?
请帮助我

解决方案

尝试

 <   a  > ; 
  <!-  < b/>  ->  
  <   c    > 
<  /a  >  



在记事本或任何其他文本编辑器中打开文件,然后添加<!-->在第二个节点上.
那应该就是您所需要的.


首先,您应该知道XmlDocument 并没有给您元素在源流中的位置.

因此,您必须使用Html Agility Pack:
http://htmlagilitypack.codeplex.com/wikipage?title=Examples [ HtmlAgilityPack.HtmlDocument htmlDocument = HtmlDocument(); var content = @" ; htmlDocument.LoadHtml(content); var requiredNode = htmlDocument.DocumentNode.SelectNodes(" )[" ); content = content.Insert(desiredNode.StreamPosition," );

记住要添加一些错误检查.

希望对您有所帮助.


hi all,
i''ve one xml file as follows

<a>
  <b />
  <c />
</a>


now i want to change the xml as follows

<a>
 <!-- <b /> -->
 <c />
</a>


how can i move with this?
please help me

Try

<a>
  <!--<b />-->
  <c />
</a>



Open you file in notepad or any other text editor and add <!-- --> on the second node.
That should be all you need.


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.


这篇关于如何注释一个xml节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆