Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to insert new components such as new tags to existing XML using C#


How to do this
Posted
Comments
Sergey Alexandrovich Kryukov 18-Mar-14 0:40am    
Do you mean new element? Or new attribute? What's the problem?
—SA
KUMAR619 18-Mar-14 0:41am    
New node not attribute
Sergey Alexandrovich Kryukov 18-Mar-14 0:43am    
Parse it to memory, add new element, generate new XML text.
—SA
KUMAR619 18-Mar-14 0:48am    
How to do so

I have saved XML already.

Then I want to add new node such as salary node in all records node

Can you get me a code snippet for me to understand

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Mar-14 0:56am    
5ed. I answered in a different way...
—SA
Abhinav S 18-Mar-14 2:40am    
Thank you.
XML reading and generation is offered by .NET FCL in different ways. You can select the one most convenient for your case. This is my short overview of them:

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlTextWriter and System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].


—SA
 
Share this answer
 
Comments
Abhinav S 18-Mar-14 2:40am    
5.
Sergey Alexandrovich Kryukov 18-Mar-14 10:37am    
Thank you, Abhinav.
—SA

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