Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can some one help me with writing a small function (not more than 10 lines ) for writing the following xml (file name 1.xml) using C#?

XML
<items>
  <item id="test"/>
  </item>
</items>
Posted
Updated 27-Oct-10 7:47am
v3

Easiest way would be using File.WriteAllText:

See http://msdn.microsoft.com/en-us/library/ms143375.aspx[^]

Example:

C#
string xml = @"<items>
  <item id="test"/>
  </item>
</items>";

File.WriteAllText(@"d:\files\1.xml", xml);
 
Share this answer
 
Comments
Abhinav S 27-Oct-10 13:55pm    
Good answer.
It depends what you are actually trying to achieve, for example if you want to store an object as a text file you can use serialization, google for C# XML Serialization and you'll get lots of examples..
 
Share this answer
 
printf("%s", "1.xml");

If you mean writing the contents then there are various helper libraries around to do it for you.
 
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