title: Writing/ Reading Multiple Objects into Xml C#
body: <p>I am new to Xml and have written the code whcih creates an Xml and Reads it back also.
  But i want to have some modifications in the Xml structure.</p>
  
  <p>What i don't want is ArrayOfMovie tag, which is coming as the root tab.
  But when i am writing multiple objects into the Xml it shows an ArrayOfMovie tag. As i have to maintain the structure of the class, the upper tag as Movie, then its details and then other movie. Also please if you tell the code to modify the xml, tell the procedure to read the newly structured xml too.</p>
  
  <p>Here is the code for the scenario:</p>
  
  <pre><code>// Movies class which contains the list of Movie objects
   public class Movies
      {
       public List&lt;Movie&gt; movieList = new List&lt;Movie&gt;();
  
      }
  
    //Movie class
    public class Movie
      {
  
          public string Title
          { get; set; }
  
  
          public int Rating
          { get; set; }
  
  
          public DateTime ReleaseDate
          { get; set; }
  
      }
  
      private void CreateXml_Click(object sender, EventArgs e)
      {
          string filePath = path + textBox_XmlFileName.Text+".xml";
  
          Movie firstMov = new Movie();
          firstMov.Title = "Shrek";
          firstMov.Rating = 2;
          firstMov.ReleaseDate = DateTime.Now;
  
          Movie secondMov = new Movie();
          secondMov.Title = "Spider Man";
          secondMov.Rating = 4;
          secondMov.ReleaseDate = DateTime.Now;
  
          Movies moviesObj = new Movies();
          moviesObj.movieList.Add(firstMov);
          moviesObj.movieList.Add(secondMov);
          List&lt;Movie&gt; movList = new List&lt;Movie&gt;() { firstMov,secondMov};
  
          XmlHandler.SerializeToXml(moviesObj.movieList, filePath);
  
      }
  
  // The static class and funcion that creates the xml file 
         public static void SerializeToXml(List&lt;Movie&gt; movies ,string filePath)
         {
            XmlSerializer xls= new XmlSerializer(typeof(List&lt;Movie&gt;)); 
  
         TextWriter tw = new StreamWriter(filePath);
         xls.Serialize(tw, movies);
         tw.Close();
         }
  </code></pre>
  
  <p>// It Creates the following output</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ArrayOfMovie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Movie&gt;
      &lt;Title&gt;Shrek&lt;/Title&gt;
      &lt;Rating&gt;2&lt;/Rating&gt;
      &lt;ReleaseDate&gt;2014-05-25T22:55:17.2811063+05:00&lt;/ReleaseDate&gt;
    &lt;/Movie&gt;
    &lt;Movie&gt;
      &lt;Title&gt;Spider Man&lt;/Title&gt;
      &lt;Rating&gt;4&lt;/Rating&gt;
      &lt;ReleaseDate&gt;2014-05-25T22:55:17.2811063+05:00&lt;/ReleaseDate&gt;
    &lt;/Movie&gt;
  &lt;/ArrayOfMovie&gt;
  </code></pre>
  
  <p>// The code for reading the file into objects</p>
  
  <pre><code>  public static List&lt;Movie&gt; DeserializeFromXml(string filePath)
     {
         XmlSerializer deserializer = new XmlSerializer(typeof(List&lt;Movie&gt;));
         TextReader tr = new StreamReader(@filePath);
         List&lt;Movie&gt; movie;
         movie = (List&lt;Movie&gt;)deserializer.Deserialize(tr);
         tr.Close();
  
         return movie;
     }
  </code></pre>