Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VC6
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 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 Sergey Alexandrovich Kryukov 240
1 CHill60 210
2 Peter Leow 170
3 Richard MacCutchan 169
4 Richard Deeming 166
0 Sergey Alexandrovich Kryukov 9,238
1 OriginalGriff 6,806
2 Peter Leow 4,432
3 Zoltán Zörgő 3,919
4 Richard MacCutchan 2,782

Advertise | Privacy | Mobile
Web02 | 2.8.150129.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