简体   繁体   English

如何创建列表<string>从简单的xml文件?

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

this is the xml这是 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我需要阅读这个 xml 文件并创建一个包含

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

what is the simple and fast way to do it ?什么是简单快捷的方法?

You can use LinqToXml您可以使用 LinqToXml

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

使用 XML 阅读器和编解码器将 DOM 树转换为列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM