开发者

c# xmlarray and xmlarrayitem

I'm trying to use XMLSerializer and have the following code:

[XmlArray("ToggleExclusion")]
    [XmlArrayItem("Result")]
    public string[] toCopy { get; set; }

And I serialise as such:

XmlSerializer x = new XmlSerializer(typeof(string[]));

       StringWriter w = new StringWriter();
       x.Serialize(w, toCopy);
开发者_如何学Go

However, when the xml is printed, the elements are: typeofstring, and string.

What am I missing here to ensure the elements are as I want above.


You need to use XmlRoot for the root item. It ignores the XmlArray or XmlElement tag for the root.

You may also specify the root name in the XmlSerializer constructor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜