title: Create XML file from collection list
body: <p>I have a collection string with information about customers like name, gender etc. All custumers have an id.</p>
  
  <p>Now i want to create a common XML file with all customers in it. Something like example below:</p>
  
  <pre><code>&lt;custumers&gt;
    &lt;custumer&gt;
        &lt;name&gt;&lt;/name&gt;
         &lt;id&gt;&lt;/id&gt;
         &lt;etc&gt;&lt;/etc&gt;
    &lt;/custumer&gt;
  &lt;/custumers&gt;
  </code></pre>
  
  <p>The start up with no XML file is easy, I used linq to create the xml file.</p>
  
  <p>For initial creation I used following code:</p>
  
  <pre><code>try
  {
      var xEle = new XElement("Customers",
      from cus in cusList
          select new XElement("Customer",
             new XElement("Name", cus.Name),
             new XElement("gender", cus.gender),
             new XElement("etc", cus.etc));
  }
  xEle.Save(path);
  </code></pre>
  
  <p>But on the point if i want to update the XML file i get some problems to get it.
  My approach to solve it:</p>
  
  <pre><code>Iterate over all customers in list and check for all customers if the customer.id exists in the XML.
  IF not: add new customer to xml  
  IF yes: update values
  </code></pre>
  
  <p>My code so far:</p>
  
  <pre><code>var xEle = XDocument.Load(xmlfile);
  foreach (cus in cusList)
  try
  {
      var cids = from cid in xEle.Descendants("ID")
                 where Int32.Parse(xid.Element("ID").Value) == cus.ID          
                 select new XElement("customer", cus.name),
                    new XElement ("gender"), cus.gender),
                    new XELement ("etc."), cus.etc) 
  
          );
         xEle.Save(xmlpath);
  }
  </code></pre>