Click here to Skip to main content
11,802,442 members (71,087 online)
Rate this: bad
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 18:44pm
Edited 13-Dec-11 18: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 at 14-Dec-11 1:05am
how can i do this by code?
Abhinav S at 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 at 14-Dec-11 2:58am
+5 for the link ;)
Shakti Misra at 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 at 14-Dec-11 1:29am
okay..thank you
Abhinav S at 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 at 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
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web01 | 2.8.151002.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