I am trying to parse a file (iTunes playlist) using XLinq, but the way the dictionary is setup in the file is causing issue. Its looking for an element called Name, and not looking at key/value combo. Anybody know how to fix the issue?
TextReader
reader = new StreamReader(filepath);XMLList. =
XElement.Load(reader);foreach
(XElement x in XMLList.Elements("dict")){
Song s = new Song{Name=(string)x.Element("Name")};}
File looks like.....
860
TrackID
1017
Name
Stage
Artist
Live
Composer
Ed Kowalczyk, Chad Taylor, Patrick Dahlheimer, Chad Gracey
Album
Throwing Copper
LukePosted Mar 26, 2008, 1:35 PM
I actually figured out how to do it.
foreach
(XElement x in XMLList.Elements("dict")){
Song s = new Song(); foreach (XElement xInside in x.Elements("key")) //loop through all the keys{
if
((string)xInside.Value == "Artist")s.Artist = (((
XElement)xInside.NextNode).Value).ToString(); //go to next element, cast it to Xelement else if ((string)xInside.Value == "Name")s.Name = (((
XElement)xInside.NextNode).Value).ToString();}
if (s != null && s.Artist != null)List.Add(s);