读取XML数据到一个数组 [英] Reading data from XML into an array

查看:125
本文介绍了读取XML数据到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件,在其中我节省临时数据(指数和放大器;列名)下面给出:

I've an XML file, in which I'm saving temporary data(index & name of columns) as given below:

-<NewDataSet> 
    -<USERROWCOL> 
          <COL>2</COL> 
          <Name>Name</Name> 
     </USERROWCOL> 
    -<USERROWCOL> 
          <COL>8</COL> 
          <Name>PDC</Name> 
     </USERROWCOL>
 <NewDataSet>

我想用C#中的数组读取所有 COL 就像这将是一个数组( {2,8} )。谁能帮我这个?

I want to read all COLs in an array using C# like it will be an array( {2, 8} ). Can anyone help me about this?

推荐答案

下面是一个LINQ到XML版本:

Here is a LINQ to XML Version:

string[] arr = XDocument.Load(@"C:\xxx.xml").Descendants("Name")
                        .Select(element => element.Value).ToArray();

这将使所有的名称元素的文档。

This will give all the Name element from the document.

这篇关于读取XML数据到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆