将xml列表数据转换为datatable

时间:2016-08-13 06:09:14

标签: xml linq c#-4.0 linq-to-xml

我是c#的初学者,我只是想读取一个xml并将xml列表数据返回给数据表。这是我的代码。

 public DataTable SearchData(string sData)
        {
            userdata objuserdata = new userdata();
            string Xmlpath = @"d:\Test.xml";


            var Data = XDocument.Load(Xmlpath).Root
                       .Descendants("Field")
                       .Where(element => element.Attribute("Title").Value == "XYZ")
                       .Descendants()
                       .Where(element => element.Name == "Description"
                                         )
                       .Select(element => element.Value).ToList();

            // convert var data to datatable
            //return datatable;
        }

如何将数据转换为数据表。有人可以帮助我

1 个答案:

答案 0 :(得分:0)

代码看起来像这样:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.amazon.android:mobile-ads:5.+'
}