C# xml linq for this kind of file.

mion shion 241 Reputation points
2021-03-27T02:43:57.567+00:00

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....
B0qC3hLB

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

kind regards elfenliedtopfan5

C#
C#
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.
10,245 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2021-03-27T07:00:38.597+00:00

    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