Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write xml file using C#

Tags:

c#

asp.net

I am newer person in c# asp.net . I want to write xml file in c# code behind file in my asp.net web application and pass this xml file as a string to a webservice . Can any one able to help me its will very useful for my project . Thank you

like image 749
sanakkian Avatar asked May 16 '26 10:05

sanakkian


1 Answers

As "fiver" had mentioned you could use the XmlDocument or the new simplified version XDocument for creating XML Documents. Here's a sample code snippet from MSDN for creating XML documents and writing to a file.

XDocument doc = new XDocument(
    new XElement("Root",
        new XElement("Child", "content")
    )
);
doc.Save("Root.xml");

This will write the following text to the xml file

<?xml version="1.0" encoding="utf-8"?>
<Root>
  <Child>content</Child>
</Root>

Note: XDocument is supported only on .NET framework 3.5 and above

like image 67
AbrahamJP Avatar answered May 18 '26 23:05

AbrahamJP