Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am new to xml, how to create xml file like below formate
please give me the codings in c#.

XML
<Countries>
  <Country name ="ANDORRA">
    <state>Andorra (general)</state>
    <state>Andorra</state>
  </Country>
  <Country name ="United Arab Emirates">
    <state>Abu Z¸aby</state>
    <state>Umm al Qaywayn</state>
  </Country>


thanks in advance...!
Posted
Comments
Bama Boy 4-Oct-13 8:56am    
right click on project and add xml file and you can write there
Sergey Alexandrovich Kryukov 4-Oct-13 8:59am    
5! :-)
—SA
Jameel VM 4-Oct-13 8:59am    
please elaborate your requirement. from where you want to create the xml file
Bama Boy 4-Oct-13 9:03am    
click on your project and click on add new item and there choose xml file

1 solution

There are different ways to parse and compose XML document programmatically provided by .NET FCL, please see my quick overview:

  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[^].


Good luck,
—SA
 
Share this answer
 
Comments
Abhinav Gauniyal 4-Oct-13 18:20pm    
Ha :)
Sergey Alexandrovich Kryukov 4-Oct-13 19:40pm    
:-)

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