Yanshof
Yanshof

Reputation: 9926

How to create a list<string> from simple xml file?

this is the xml

<Basic>
  <Results>
    <Result>a1</Result>
    <Result>a2</Result>
    <Result>a3</Result>
  </Results>
</Basic>

I need to read this xml file and create a list that will contain

list[0] = a1   
list[1] = a2   
list[2] = a3   

what is the simple and fast way to do it ?

Upvotes: 1

Views: 1085

Answers (2)

Eser
Eser

Reputation: 12546

You can use LinqToXml

var list = XDocument.Load(filename)
           .Descendants("Result")
           .Select(x => (string)x)
           .ToList();

Upvotes: 4

iAdjunct
iAdjunct

Reputation: 2979

With an XML reader and a codec to convert the DOM tree to a list.

Upvotes: 1

Related Questions