Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi all,
i've one xml file as follows
XML
<a>
  <b />
  <c />
</a>

now i want to change the xml as follows
XML
<a>
 <!-- <b /> -->
 <c />
</a>

how can i move with this?
please help me
Posted
Updated 13-Dec-11 18:50pm
v5

Try
XML
<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.
 
Share this answer
 
v2
Comments
Jijesh Balakrishnan b 14-Dec-11 1:05am    
how can i do this by code?
Abhinav S 14-Dec-11 1:19am    
http://www.ucancode.net/CPP_Library_Control_Tool/VC-XML-Read-Write-Create-Processing-XML-Document-Article--Source-Code.htm might help. Basically you need to read the xml and then write it back into the file (with your changes).
Amir Mahfoozi 14-Dec-11 2:58am    
+5 for the link ;)
BrainlessLabs.com 14-Dec-11 1:17am    
What parser you are using?
You basically have to fetch the node, remove it, and add a comment in the xml stream.
Jijesh Balakrishnan b 14-Dec-11 1:29am    
okay..thank you
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 :

C#
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.
 
Share this answer
 
Comments
Jijesh Balakrishnan b 14-Dec-11 2:55am    
thank you for your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900