在C#转换对象数组到XML [英] Converting array of objects to XML in C#
本文介绍了在C#转换对象数组到XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有没有内置的转换器对象数组转换为XML。有没有创建一个XML列的阵列来帮我做的LINQ to XML这一个又一个的XML我之间加入一个快速简陋的方法是什么?
I know there's no built in converter to convert an array of objects to XML. Is there a quick rudimentary way to create a XML out of the array to help me do a LINQ to XML join between this one and another XML I have?
推荐答案
您可以使用LINQ到XML,它是很容易从现有的数据结构,XML映射,即:
You can use Linq to XML, it is really easy to map from your existing data structures to XML, i.e.:
int[] values = { 1, 2, 17, 8 };
XDocument doc = new XDocument();
doc.Add(new XElement("root", values.Select( x=> new XElement("item", x))));
产生下面的输出:
produces the following output:
<root>
<item>1</item>
<item>2</item>
<item>17</item>
<item>8</item>
</root>
这篇关于在C#转换对象数组到XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文