title: Serialize data to XML and CSV
body: <p>I have two problem. I need to serialize data to csv and xml but its turn out to be problematic for me.</p>
  
  <p>As xml I desire to get something like:</p>
  
  <pre><code>&lt;sentence&gt;
   &lt;word&gt;example1&lt;/word&gt;
   &lt;word&gt;example2&lt;/word&gt;
   &lt;word&gt;example3&lt;/word&gt;
  &lt;/sentence&gt;
  &lt;sentence&gt;
   &lt;word&gt;example1&lt;/word&gt;
   &lt;word&gt;example2&lt;/word&gt;
   &lt;word&gt;example3&lt;/word&gt;
  &lt;/sentence&gt;
  </code></pre>
  
  <p>My data its SentencedModel which contain inside collection of WordsModel. So it like: <code>List&lt;ICollection&lt;string&gt;&gt;.</code> Every position (sentence) in list have collection of string (words).
  Class look like:</p>
  
  <pre><code>[Serializable]
  public class WordsModel : IEnumerable&lt;string&gt;
  {
      [XmlRoot("Word")]
      public ICollection&lt;string&gt; Words { get; set;}
  
      public IEnumerator&lt;string&gt; GetEnumerator()
      {
          return this.Words.GetEnumerator();
      }
  
      IEnumerator IEnumerable.GetEnumerator()
      {
          return this.Words.GetEnumerator();
      }
  }
  
  [Serializable]
  public class SentencedModel : IEnumerable&lt;WordsModel&gt;
  {
      [XmlArray("Sentence"), XmlArrayItem(typeof(WordsModel), ElementName = "Words")]
      public ICollection&lt;WordsModel&gt; Sentences { get; set; }
  
      public SentencedModel()
      {
          this.Sentences = new List&lt;WordsModel&gt;();
      }
  
      public void Add(WordsModel words)
      {
          this.Sentences?.Add(words);
      }
  
      public IEnumerator&lt;WordsModel&gt; GetEnumerator()
      {
          return this.Sentences.GetEnumerator();
      }
  
      IEnumerator IEnumerable.GetEnumerator()
      {
          return this.Sentences.GetEnumerator();
      }
  }
  </code></pre>
  
  <p>My class which is Repositories for that:</p>
  
  <pre><code>public class WordsSeperapedBySentence
  {
      public SentencedModel WordsSeperatedBySentence { get; }
  
      public WordsSeperapedBySentence()
      {
          this.WordsSeperatedBySentence = new SentencedModel();
      }
  
      public bool AddSentence(ICollection&lt;string&gt; words)
      {
          if (words == null) return false;
          WordsModel wordsModel = new WordsModel();
          wordsModel.Words = words;
          this.WordsSeperatedBySentence.Add(wordsModel);
          return true;
      }
  }
  </code></pre>
  
  <p>Here is my serializer class:</p>
  
  <pre><code>public class SerializeData
  {
      public string SerializeToXml(SentencedModel data)
      {
          XmlSerializer xmlSerializer = new XmlSerializer(typeof(SentencedModel));
          using (StringWriter textWriter = new StringWriter())
          {
              xmlSerializer.Serialize(textWriter, data);
              return textWriter.ToString();
          }
      }
  
      public ToCsv(WordsSeperapedBySentence data)
      {
          //??
      }
  }
  </code></pre>
  
  <p>But after using </p>
  
  <pre><code>List&lt;string&gt; example1 = new List&lt;string&gt;();
  example1.Add("Chris"); 
  example1.Add("call");
  example1.Add("Anna");
  
  List&lt;string&gt; example2 = new List&lt;string&gt;();
  example2.Add("Somebody");
  example2.Add("call");
  example2.Add("Wolf");
  
  WordsModel words1 = new WordsModel();
  WordsModel words2 = new WordsModel();
  words1.Words = example1;
  words2.Words = example2;
  
  SentencedModel sentenced = new SentencedModel();
  sentenced.Add(words1);
  sentenced.Add(words2);
  
  SerializeData serialize = new SerializeData();
  var stringAsResult = serialize.SerializeToXml(sentenced);
  Console.WriteLine(stringAsResult);
  </code></pre>
  
  <p>I got errors. Also I do not have idea how to storage them to CSV. 
  Could you help me?
  Thank you in advance.</p>