Click here to Skip to main content
11,933,253 members (63,334 online)
Rate this:
Please Sign up or sign in to vote.
See more: VC6 C++
hi all,
i've one xml file as follows
  <b />
  <c />
now i want to change the xml as follows
 <!-- <b /> -->
 <c />
how can i move with this?
please help me
Posted 13-Dec-11 19:44pm
Edited 13-Dec-11 19:50pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

Open you file in notepad or any other text editor and add <!-- --> on the second node.
That should be all you need.
Jijesh Balakrishnan b 14-Dec-11 1:05am
how can i do this by code?
Abhinav S 14-Dec-11 1:19am 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 ;)
Shakti Misra 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
Abhinav S 14-Dec-11 3:15am
You are welcome.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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 :[^]

Then you will have something like this :

HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlDocument();
var content =@"<a>
                      <b />
                      <c />
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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 14 Dec 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100