开发者

c# xmlarray and xmlarrayitem

开发者 https://www.devze.com 2023-02-19 04:01 出处:网络
I\'m trying to use XMLSerializer and have the following code: [XmlArray(\"ToggleExclusion\")] [XmlArrayItem(\"Result\")]

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

精彩评论

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