Hi, I'm trying to insert an element at a specific point within my file, then save that file out. However, I can't seem to get it right. My XML layout is like this:
<?xml version="1.0" encoding="utf-8"?>
<Settings>
<Items />
<Users />
</Settings>
This is my current code:
XDocument xd = XDocument.Load(@"C:\test.xml");
var newPosition = xdoc.Root.Elements("Users");
//I've tried messing around with newPosition methods
XElement newItem = new XElement("User",
new XAttribute("Name", "Test Name"),
new XAttribute("Age", "34"),
);
//how can I insert 'newItem' into the "Users" element tag in the XML file?
xd.Save(new StreamWriter(@"C:\test.xml"));
I'd like to use Linq to XML to insert 'newItem' into the tag. Thanks for any help on this.