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:
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);
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:
<Snippet name="snippet name">
<SnippetCode>
code goes here
</SnippetCode>
</Snippet>
Try this code :