开发者

Serializing a System.Array to a XML String

I need to pass an array of strings to SQL Server 2005, and so I wrote a stored procedure which accpets a XML parameter and deals with it properly. My question is if there is any easy way to serialize a string[] to a XML string (not a file in开发者_开发知识库 the disk) directly in C# without having to code my own method using XDocument, XAttribute and the like.

Example: I want to be able to transform something like new string[] { "a", "b", "c" } into something like

<StringList><String>a</String><String>b</String><String>c</String></StringList>

Element tag names are unimportant.


You could try XmlSerializer if you really want to avoid writing your own code, but doing it with LINQ to XML would be as simple as:

XElement element = new XElement("StringList",
                                values.Select(x => new XElement("String", x)));
string text = element.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜