I have this XML file:
<?xml version="1.0" encoding="utf-8"?>
<NewSounds>
<Artists>
<Artist>Avril Lavigne</Artist>
<Artist>Bob Marley</Artist>
<Artist>Coldplay</Artist>
</Artists>
<Genres>
<Genre>Rock</Genre>
<Genre>Jazz</Genre>
<Genre>Metal</Genre>
</Genres>
</NewSounds>
How do I parse this simple XML file in LINQ? I know very little about LINQ, this is what I have:
var artists = xml.Descendants("Artists")
.Elements("Artist")
.Select(a => new Artist {
Name = a.Element("Artist").Value
}).ToArray();
Problem is, it throws up a System.NullReferenceException: Object reference not set to an instance of an object. error on the .Select part (maybe because it can't find the value?).
I'd like to traverse the XML and grab the relevant parts inside the <Artist> and <Genre> tags.