Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6
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
Posted 13-Dec-11 19:44pm
Edited 13-Dec-11 19:50pm
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
Jijesh Balakrishnan b at 14-Dec-11 1:05am
   
how can i do this by code?
Abhinav S at 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 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
good
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 :
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.
  Permalink  
Comments
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 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 14 Dec 2011
Copyright © CodeProject, 1999-2014
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