C# xml linq for this kind of file.

mion shion 241 Reputation points

hello all i did get support the other week and been looking into linq as suggested,

and been looking into it now if i am not mistaken this should work

            XDocument xdoc = new XDocument();

            xdoc = XDocument.Load(@"C:\Users\elfen\AppData\Local\PCDJ-DEX3\Database\Database.xml");

            var result = from q in xdoc.Descendants("tracks")
                         select new
                             artist = q.Element("arti").Value,
                             title = q.Element("titl").Value,
                             filename = q.Element("fnam").Value


and xml file....

not sure gone through loads of guides cant see why its not picking these up.

kind regards elfenliedtopfan5

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,478 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 106.4K Reputation points

    Check this code:

    var result = from q in xdoc.Root.Elements( "tracks" ).Elements( "track" )
                    select new
                        artist = q.Attribute( "arti" )?.Value,
                        title = q.Attribute( "titl" )?.Value,
                        filename = q.Attribute( "fnam" )?.Value
    var list = result.ToList( );
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful