title: C# how to add elements to a xml file
body: <p>I'm using WinForms .NET 2.0 for my application. Previously, I used NET 4.0 to add an element to an existing XML file in this way:</p>
  
  <pre><code>        XDocument doc = XDocument.Load(spath);
          XElement root = new XElement("Snippet");
          root.Add(new XAttribute("name", name.Text));
          root.Add(new XElement("SnippetCode", code.Text));
          doc.Element("Snippets").Add(root);
          doc.Save(spath);
  </code></pre>
  
  <p>Where spath is the path of the XML file. I am having trouble degrading this code to .NET 2.0 since the syntax is confusing, can someone help me? I'm trying to add an element with an attribute and element like this:</p>
  
  <pre><code>&lt;Snippet name="snippet name"&gt;
      &lt;SnippetCode&gt;
      code goes here
      &lt;/SnippetCode&gt;
    &lt;/Snippet&gt;
  </code></pre>