I got a function that saves the data from a List to a XML file. My question is, how can I actually load the XML file into a List?
My XML file:
<Customers>
<customer ID="0" firstname="xx" lastname="xx" />
</Customers>
I got a function that saves the data from a List to a XML file. My question is, how can I actually load the XML file into a List?
My XML file:
<Customers>
<customer ID="0" firstname="xx" lastname="xx" />
</Customers>
using System;
using System.Linq;
using System.Xml.Linq;
public class XmlToList
{
static void Main()
{
string xml = "<Customers><customer ID=\"0\" firstname=\"xx\" lastname=\"xx\" />/Customers>";
XDocument doc = XDocument.Parse(xml);
var list = doc.Root.Elements("Customers")
.Select(node => node.Value)
.ToList();
foreach (string item in list)
{
Console.WriteLine(item);
}
}
}
You may refer to this post: https://stackoverflow.com/a/956777/3232673