Click here to Skip to main content
15,886,769 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
What is the best way to create an XML document using C#? I'm a newbie with regards to XML and was wanting some guidelines/pointers to get started. Any help would be greatly appreciated.
Posted
Updated 17-Aug-17 4:39am
Comments
[no name] 12-Sep-12 11:31am    
Reading the documentation, http://msdn.microsoft.com/en-us/library/system.xml.aspx, is a good place to start.
Sergey Alexandrovich Kryukov 12-Sep-12 18:36pm    
"Best" may means "fastest", "easiest", "most robust", you name it. So, it depends on what you want.
--SA

Based on different Scenarios you could use the following:

1. XMLSerializer : Assuming you have an object(class) and you need XML respresentation for this.
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx[^]

2. XML Writer: If You are going to create each and every item.
http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^]

3. Through DataSet's WriteXml method : Assuming you have a dataset already
http://msdn.microsoft.com/en-us/library/hb27k0tf(v=vs.90).aspx[^]

4. XMLDocument.Load
If you already have a string/stream/TextReader/XmlReader respresentation of xml.
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]
 
Share this answer
 
v2
I would suggest you to go through this: MSDN: Improving XML Performance[^]
 
Share this answer
 

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