XmlRoot() for Xml Serilization does not work

不羁的心 提交于 2019-11-29 09:25:23
burnt1ce

I found an answer to my question here:

http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/4b228734-a209-445a-991c-0420b381ac93

I just used [XmlType("")] and that worked.

using System;
using System.Xml.Serialization;


namespace CommunityServer.Scheduler
{

    [XmlType("ScheduledShowElement")]
    public class ScheduledShow
    {

      ...
    }
}

[XmlRoot(...)] only affects the outermost element (<ScheduledShows>...</ScheduledShows>). I suspect you want [XmlElement(...)]. Of course, another way is to write an object wrapper:

[XmlRoot("SheduledShows")]
public class Shows {
    [XmlElement("SheduledShowElement")]
    public List<Show> Shows {get;set;}
}

And serialize this wrapper object instead of just a list.

Hasani Blackwell

You need to use the overloaded constructor that takes in a XmlAttributeOverrides and make sure you override the name of the ScheduledShow class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!