Click here to Skip to main content
16,004,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add comments in an existing xml document.a sample xml is shown below i need to write code in c#. XML serialization was used to generate this xml
any help would be great...
thanks in advance

XML
<?xml version="1.0" encoding="utf-8"?>
<Person>
<Name>hi</Name>
<Address>10dcalp</Address>
<Age>12</Age>
</Person>
Posted
Comments
bhagirathimfs 13-Jul-12 2:29am    
You want to add comment lines in the XML file
Try this
<!--Add comment lines inside -->

C#
foreach (XElement item in doc.Descendants("NodeName"))
            {
              XElement ObjElement= item .Element("ElementName");
              XComment comm = new XComment("Add Comment Here");
              xe1.AddBeforeSelf(comm);
            }   

Iterate through the root nodes and go to your element. By using XElement'S object.AddBeforeSelf() method we can add our comments. and save the XDocument

Thank you all
 
Share this answer
 
 
Share this answer
 
Comments
ajithttges 13-Jul-12 2:32am    
Thanks Mehdi Gholam but i need to add comment after serialization and each tag need comments.

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