CSharp - Saving with XElement.Save()


The XElement class has several Save methods:

void XElement.Save(string filename);
void XElement.Save(TextWriter textWriter);
void XElement.Save(XmlWriter writer);
void XElement.Save(string filename, SaveOptions options);
void XElement.Save(TextWriter textWriter, SaveOptions options);

The following code is an example to save an XML document to a file.


using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Program/*  w w w.  j  a  v a 2s.  c om*/
    static void Main(string[] args){
          XElement bookParticipants =
            new XElement("Books",
              new XElement("Book",
                new XAttribute("type", "Author"),
                new XAttribute("experience", "first-time"),
                new XAttribute("language", "English"),
                new XElement("FirstName", "Joe"),
                new XElement("LastName", "Ruby")));

Related Topic