Csharp/C#教程:将xelement加载到数据表中分享


将xelement加载到数据表中

我有以下xml文件,其中包含很多关于公司分支机构的信息..(这只是一个例子)..

我真正需要的是,只在数据表中加载Branch1中的数据(与我的xml文件具有相同的结构,因此数据表根本没有问题)。

iam使用c#而我想这样做是linq,但我不知道linq …我的问题是:我如何从xml读取条目作为数据表行,所以我可以将它复制到我的数据表?

我现在有:

XElement main = XElement.Load("branches.xml"); IEnumerable elList = from el in main.Descendants("branch").Where(ex=>ex.Attribute("name").Value=="Branch1") select el; //this will return me the element where name =Branch1 //now, how would i only load this entry into my datatable ?? //this won`t work branchesDataTable.ReadXml(XElement el in elList); 

任何帮助真的很感激..

    
Street 1, 1234, NY
0123456789 James
Street 2, 4567, NY
9876543210 Will

尝试

上述就是C#学习教程:将xelement加载到数据表中分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 branchesDataTable.ReadXml(new StringReader(new XElement("branches", elList).ToString())); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1016777.html

(0)
上一篇 2021年12月31日
下一篇 2021年12月31日

精彩推荐