XmlRoot() for Xml Serilization does not work

前端 未结 3 2058
旧时难觅i
旧时难觅i 2020-12-18 22:58

I\'m trying to get my httphandler to print out an XML file with the format:


    ...

        
相关标签:
3条回答
  • 2020-12-18 23:09

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

    0 讨论(0)
  • 2020-12-18 23:10

    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
        {
    
          ...
        }
    }
    
    0 讨论(0)
  • 2020-12-18 23:26

    [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.

    0 讨论(0)
提交回复
热议问题