I try to get the value of "firstName" of the following XML Code:
<?xml version="1.0" encoding="utf-8"?>
<Userlist xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<user username="Max.mix" id="464" adult="true">
<registeredBy>Internet</registeredBy>
<firstName>Max</firstName>
<birthday>15031975</birthday>
</user>
<user username="Sus.lab" id="125" adult="false">
<registeredBy>Phone</registeredBy>
<firstName>Susanne</firstName>
<birthday>03112007</birthday>
</user>
</Userlist >
But I get everytime a empty (null) value back with this method:
public List<List> GetFirstName()
{
const string filename = @"C:\XML.xml";
string text = File.ReadAllText(filename);
XDocument doc = XDocument.Parse(text);
List<List> firstnameList = doc.Root.Elements().Select(x => new List
{
firstName = (string)x.Element("firstName"),
}).ToList();
return firstnameList ;
}
public class List
{
public string firstName{ get; set; }
}
Where I have the Problem?
Thank you.