本文介绍了XmlRoot()FOR XML Serilization不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的HttpHandler打印出与格式的XML文件:

 < ScheduledShows> 
< ScheduledShowElement> ...< / ScheduledShowElement>
< ScheduledShowElement> ...< / ScheduledShowElement>
< ScheduledShowElement> ...< / ScheduledShowElement>
< / ScheduledShows>



但由于某些原因,在ScheduledShow.cs属性XmlRoot(ScheduledShowElement)不工作这样我想它的工作。相反,输出我得到的是:



 < ScheduledShows> 
< ScheduledShow> ...< ScheduledShow>
< ScheduledShow> ...< ScheduledShow>
< ScheduledShow> ...< ScheduledShow
< / ScheduledShows>



基本上,节点的名称不被重写到。如何让我的XML序列化到标签节点作为?



下面是我的代码和XML输出​​。 !谢谢



OneDayScheduleHandler.cs

 使用系统; 
使用System.Collections.Generic;
使用的System.Web;

使用的System.Xml.Serialization;使用Microsoft.P​​ractices.EnterpriseLibrary.Data
;
使用System.Data.Common;
使用System.Data这;
:使用System.IO;
使用的System.Xml;
使用System.Text;
使用CommunityServer.Scheduler;
命名空间CommunityServer.Scheduler
{

公共类OneDayScheduleHandler:IHttpHandler的
{
私人只读INT NoLimitOnSize = -1;

公共无效的ProcessRequest(HttpContext的背景下)
{
INT offsetInDays,时区,大小;

的DateTime selectedDateTime;
Int32.TryParse(context.Request.QueryString [时区],出来时区);
Int32.TryParse(context.Request.QueryString [daysToOffset],出offsetInDays);
如果(!String.IsNullOrEmpty(context.Request.QueryString [大小))
{
Int32.TryParse(context.Request.QueryString [大小],出大小) ;
}
,否则
{
尺寸= NoLimitOnSize;
}

如果(时区≤(INT)ScheduleConstants.TimeZone.Eastern)
{
selectedDateTime = DateTime.Now.AddMinutes(-180);
}
,否则
{
selectedDateTime = DateTime.Now;
}
selectedDateTime = selectedDateTime.AddDays(offsetInDays);
context.Response.ContentType =文/ XML;
context.Response.Write(SerializeToXML((名单< ScheduledShow>)GetSheduledShowsByDateTime(selectedDateTime,大小)));
}

公共BOOL IsReusable
{
得到
{
返回false;
}
}



公共静态的IList< ScheduledShow> GetSheduledShowsByDateTime(DateTime的日期,INT大小)
{
名单,LT; ScheduledShow>节目=新的List< ScheduledShow>();
数据库DB = DatabaseFactory.CreateDatabase(TVScheduleSqlServer);

的DbCommand CMD = db.GetStoredProcCommand(sp_get_YTVDayShowlist);

db.AddInParameter(CMD@CurrentDay,DbType.DateTime,日期);
的IDataReader读卡器= db.ExecuteReader(CMD);
INT I = 0;
,而(reader.Read()及及(I<尺寸大小|| == -1))
{
ScheduledShow秀=新ScheduledShow();
show.AirTime = Convert.ToDateTime(读卡器[Airing_datetime]的ToString());
show.StationId = Convert.ToInt32(读卡器[Station_id]的ToString());
show.ScheduleRowId = Convert.ToInt32(读卡器[ID]的ToString());
show.StoryLine =读卡器[故事情节]的ToString()。
show.Title =读卡器[TITLE_NAME]的ToString()。
show.SimsTitleId = Convert.ToInt32(读卡器[Sims_title_id]的ToString());
show.ProgramId = Convert.ToInt32(读卡器[Program_id]的ToString());
show.Genre =读卡器[Genre_list]的ToString()。
show.ProgramName =读卡器[程序名]的ToString()。
show.ShowUrl =读卡器[ShowURL]的ToString()。
show.CssClass =读卡器[的CssClass]的ToString()。
shows.Add(显示);
I ++;
}
reader.Close();
reader.Dispose();
回报显示;
}

静态公共字符串SerializeToXML(列表< ScheduledShow>节目)
{
XmlSerializer的序列化=新的XmlSerializer(typeof运算(列表< ScheduledShow>),新XmlRootAttribute( ScheduledShows));
// StringWriter的StringWriter的=新的StringWriter();
字符串的XML;使用(MemoryStream的MemoryStream的=新的MemoryStream())
{$ B $使用B
(XmlTextWriter的XmlTextWriter的=新的XmlTextWriter(MemoryStream的,Encoding.UTF8))
{
serializer.Serialize (XmlTextWriter的,说明);使用(MemoryStream的memoryStream2 =(MemoryStream的)xmlTextWriter.BaseStream)
{
XML = UTF8ByteArrayToString(memoryStream2.ToArray())
;
}
}
}

返回XML;
}

///<总结>
/// Unicode值(UTF-8编码)的字节数组转换成完整的字符串。
///< /总结>
///< PARAM NAME =字符>的Unicode字节数组转换为字符串< /参数>
///<退货和GT;字符串从Unicode字节数组<转换; /回报>
私人静态字符串UTF8ByteArrayToString(字节[]字符)
{
UTF8Encoding编码=新UTF8Encoding();
字符串constructedString = encoding.GetString(字符);
回报(constructedString);
}
}
}



ScheduledShow.cs

 使用系统; 
使用的System.Xml.Serialization;


命名空间CommunityServer.Scheduler
{

[XmlRoot(ScheduledShowElement)]
公共类ScheduledShow
$ { b
$ b〔的XmlElement(通话时间)]
公众的DateTime开播
{搞定;组; }

[的XmlElement(的stationID)]
公众诠释的stationID
{搞定;组; }

[的XmlElement(ScheduleRowId)]
公众诠释ScheduleRowId
{搞定;组; }

[的XmlElement(故事)]
公共字符串故事情节
{搞定;组; }

[XmlElement的(标题)]
公共字符串标题
{搞定;组; }

[的XmlElement(ProgramId)]
公众诠释ProgramId
{搞定;组; }

[的XmlElement(类型)]
公共字符串类型
{搞定;组; }

[的XmlElement(ProgramName中)]
公共字符串Prog​​ramName中
{搞定;组; }

[的XmlElement(SimsTitleId)]
公众诠释SimsTitleId
{搞定;组; }

[的XmlElement(ShowUrl)]
公共字符串ShowUrl
{搞定;组; }

[的XmlElement(的CssClass)]
公共字符串的CssClass
{搞定;组; }

}
}



XML文件的输出

 <?XML版本=1.0编码=UTF-8>?; 
< ScheduledShows的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema>
< ScheduledShow>
<通话时间的xmlns =htt​​p://example.books.com> 2009-09-17T10:20:00< /开播>
<的stationID的xmlns =htt​​p://example.books.com> 770 LT; /&的stationID GT;
< ScheduleRowId的xmlns =htt​​p://example.books.com> 17666100< / ScheduleRowId>
<故事情节的xmlns =htt​​p://example.books.com>在杜利展示他的最新爱好,魔术,薇拉有想法。一个巨大的后院魔术表演!主演大Doolini和他惊人的大象消失的把戏!不幸的是,娄大象误解,认为威拉希望他消失真实的。在表演中薇拉必须找到娄道歉,所以他和放大器;放大器; rsquo的;会再次出现! /当动物和薇拉发现在自己的后院一个鸡蛋,他们的父母礼踢。尤其是当涉及杜利一个关于他们看到的第一个年轻的小家伙刚孵化印迹的factoid。薇拉&放大器;放大器; rsquo的; S小动物争夺鸡蛋看的权利,使他们能够首先被称为妈妈!或波帕<!/剧情>
<标题的xmlns =htt​​p://example.books.com>玩消失/大Eggspectations< /标题>
< ProgramId的xmlns =htt​​p://example.books.com> 2202 LT; / ProgramId>
<体裁的xmlns =htt​​p://example.books.com>动画< /类型>
< ProgramName中的xmlns =htt​​p://example.books.com>威拉的野生动物和LT; / ProgramName中>
< SimsTitleId的xmlns =htt​​p://example.books.com> 68914< / SimsTitleId>
< ShowUrl的xmlns =htt​​p://example.books.com> willas_wildlife< / ShowUrl>
<的CssClass的xmlns =htt​​p://example.books.com>没有< /的CssClass>
< / ScheduledShow>
< ScheduledShow>
<通话时间的xmlns =htt​​p://example.books.com> 2009-09-17T10:45:00< /开播>
<的stationID的xmlns =htt​​p://example.books.com> 770 LT; /&的stationID GT;
< ScheduleRowId的xmlns =htt​​p://example.books.com> 17666105< / ScheduleRowId>
<故事情节的xmlns =htt​​p://example.books.com>其和放大器;放大器; rsquo的; S俱乐部一天在Gloomsville。该团伙分裂出来组成的俱乐部,为俱乐部和放大器准备;放大器; rsquo的; S在大阅兵Gloomsville外观。骷髅男孩构成了所有最酷的俱乐部有了一些新的爵士乐骨骼的朋友,没有人见过。起初,没有人相信骷髅男孩有这些新的朋友,因为他们想与他们见面,每次,它们就会消失。如果按下细节,她承认她还没和放大器;放大器; rsquo的;吨满足他们尚未和放大器;放大器; ndash的;他们和放大器;放大器; rsquo;再想象。 < /剧情>
<标题的xmlns =htt​​p://example.books.com>骷髅男孩别哭< /标题>
< ProgramId的xmlns =htt​​p://example.books.com> 1418< / ProgramId>
<体裁的xmlns =htt​​p://example.books.com>动画< /类型>
< ProgramName中的xmlns =htt​​p://example.books.com>红宝石幽暗< / ProgramName中>
< SimsTitleId的xmlns =htt​​p://example.books.com> 54297< / SimsTitleId>
< ShowUrl的xmlns =htt​​p://example.books.com> ruby​​gloom< / ShowUrl>
<的CssClass的xmlns =htt​​p://example.books.com>没有< /的CssClass>
< / ScheduledShow>
< ScheduledShow>
<通话时间的xmlns =htt​​p://example.books.com> 2009-09-17T11:10:00< /开播>
<的stationID的xmlns =htt​​p://example.books.com> 770 LT; /&的stationID GT;
< ScheduleRowId的xmlns =htt​​p://example.books.com> 17666113< / ScheduleRowId>
<故事情节的xmlns =htt​​p://example.books.com>在疯狂的玛格丽特被被困在一个罐子里,她成为娱乐Erky./Erky和活泼的来源需要一个住的地方,谁更好地发现它对于他们比弗伦泽尔< /剧情>
<标题的xmlns =htt​​p://example.books.com> Erky的生日/地点位置和LT; /标题>
< ProgramId的xmlns =htt​​p://example.books.com> 1347< / ProgramId>
<体裁的xmlns =htt​​p://example.books.com>动画< /类型>
< ProgramName中的xmlns =htt​​p://example.books.com> Erky佩基< / ProgramName中>
< SimsTitleId的xmlns =htt​​p://example.books.com> 49009< / SimsTitleId>
< ShowUrl的xmlns =htt​​p://example.books.com> erky_perky< / ShowUrl>
<的CssClass的xmlns =htt​​p://example.books.com>没有< /的CssClass>
< / ScheduledShow>
< ScheduledShow>
<通话时间的xmlns =htt​​p://example.books.com> 2009-09-17T11:35:00< /开播>
<的stationID的xmlns =htt​​p://example.books.com> 770 LT; /&的stationID GT;
< ScheduleRowId的xmlns =htt​​p://example.books.com> 17666116< / ScheduleRowId>
<故事情节的xmlns =htt​​p://example.books.com>梗概:Joyco玩具公司已经听说过乔治和他的Zoopercar,他们想销售它作为其最新的玩具。但乔治没有兴趣出售他的珍贵的交通方式。毕竟,他和他的父亲建立了它在一起,没有人能够从他采取特殊的感情了。但有两个Joyco玩具雇员,巴里和史蒂夫,还有其他的计划。如果乔治不卖给他们,他们就只能把它,他们做的。但是,一旦他们的老板,大爱德容易发现乔治的是< /剧情>
<标题的xmlns =htt​​p://example.books.com> ZOOPERCAR CAPER< /标题>
< ProgramId的xmlns =htt​​p://example.books.com> 311 LT; / ProgramId>
<体裁的xmlns =htt​​p://example.books.com/>
< ProgramName中的xmlns =htt​​p://example.books.com>乔治收缩和LT; / ProgramName中>
< SimsTitleId的xmlns =htt​​p://example.books.com> 25371< / SimsTitleId>
< ShowUrl的xmlns =htt​​p://example.books.com/>
<的CssClass的xmlns =htt​​p://example.books.com>没有< /的CssClass>
< / ScheduledShow>
< ScheduledShow>
<通话时间的xmlns =htt​​p://example.books.com> 2009-09-17T11:35:00< /开播>
<的stationID的xmlns =htt​​p://example.books.com> 770 LT; /&的stationID GT;
< ScheduleRowId的xmlns =htt​​p://example.books.com> 17666116< / ScheduleRowId>
<故事情节的xmlns =htt​​p://example.books.com>梗概:Joyco玩具公司已经听说过乔治和他的Zoopercar,他们想销售它作为其最新的玩具。但乔治没有兴趣出售他的珍贵的交通方式。毕竟,他和他的父亲建立了它在一起,没有人能够从他采取特殊的感情了。但有两个Joyco玩具雇员,巴里和史蒂夫,还有其他的计划。如果乔治不卖给他们,他们就只能把它,他们做的。但是,一旦他们的老板,大爱德容易发现乔治的是< /剧情>
<标题的xmlns =htt​​p://example.books.com> ZOOPERCAR CAPER< /标题>
< ProgramId的xmlns =htt​​p://example.books.com> 311 LT; / ProgramId>
<体裁的xmlns =htt​​p://example.books.com/>
< ProgramName中的xmlns =htt​​p://example.books.com>乔治收缩和LT; / ProgramName中>
< SimsTitleId的xmlns =htt​​p://example.books.com> 25371< / SimsTitleId>
< ShowUrl的xmlns =htt​​p://example.books.com> george_shrinks< / ShowUrl>
<的CssClass的xmlns =htt​​p://example.books.com>没有< /的CssClass>
< / ScheduledShow>
< / ScheduledShows>


解决方案

我找到了答案,在这里我的问题:





我只是用 [XmlType将()] 和工作。

 使用系统; 
使用的System.Xml.Serialization;


命名空间CommunityServer.Scheduler
{

[XmlType将(ScheduledShowElement)]
公共类ScheduledShow
$ { b
$ b:
}
}


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

<ScheduledShows>
    <ScheduledShowElement>...</ScheduledShowElement>
    <ScheduledShowElement>...</ScheduledShowElement>
    <ScheduledShowElement>...</ScheduledShowElement>
</ScheduledShows>

But for some reason, the attribute XmlRoot("ScheduledShowElement") in ScheduledShow.cs is not working the way i want it to work. Instead, the output i get is:

<ScheduledShows>
    <ScheduledShow>...<ScheduledShow>
    <ScheduledShow>...<ScheduledShow>
    <ScheduledShow>...<ScheduledShow
</ScheduledShows>

Basically, the name of the node is not being overriden to . How do i get my xml serializer to label nodes as ?

Below is my code and xml output. Thanks!

OneDayScheduleHandler.cs

using System;
using System.Collections.Generic;
using System.Web;

using System.Xml.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.IO;
using System.Xml;
using System.Text;
using CommunityServer.Scheduler;
namespace CommunityServer.Scheduler
{

    public class OneDayScheduleHandler : IHttpHandler
    {
        private readonly int NoLimitOnSize = -1;

        public void ProcessRequest(HttpContext context)
        {
            int offsetInDays, timezone, size;

            DateTime selectedDateTime;
            Int32.TryParse(context.Request.QueryString["timezone"], out timezone);
            Int32.TryParse(context.Request.QueryString["daysToOffset"], out offsetInDays);
            if (!String.IsNullOrEmpty(context.Request.QueryString["size"]))
            {
                Int32.TryParse(context.Request.QueryString["size"], out size);
            }
            else
            {
                size = NoLimitOnSize; 
            }

            if (timezone < (int)ScheduleConstants.TimeZone.Eastern)
            {
                selectedDateTime = DateTime.Now.AddMinutes(-180);
            }
            else
            {
                selectedDateTime = DateTime.Now;
            }
            selectedDateTime = selectedDateTime.AddDays(offsetInDays);
            context.Response.ContentType = "text/xml";
            context.Response.Write(SerializeToXML((List<ScheduledShow>)GetSheduledShowsByDateTime(selectedDateTime, size)));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }



        public static IList<ScheduledShow> GetSheduledShowsByDateTime(DateTime date, int size)
        {
            List<ScheduledShow> shows = new List<ScheduledShow>();
            Database db = DatabaseFactory.CreateDatabase("TVScheduleSqlServer");

            DbCommand cmd = db.GetStoredProcCommand("sp_get_YTVDayShowlist");

            db.AddInParameter(cmd, "@CurrentDay", DbType.DateTime, date);
            IDataReader reader = db.ExecuteReader(cmd);
            int i = 0;
            while (reader.Read() && (i < size || size == -1))
            {
                ScheduledShow show = new ScheduledShow();
                show.AirTime = Convert.ToDateTime(reader["Airing_datetime"].ToString());
                show.StationId = Convert.ToInt32(reader["Station_id"].ToString());
                show.ScheduleRowId = Convert.ToInt32(reader["id"].ToString());
                show.StoryLine = reader["StoryLine"].ToString();
                show.Title = reader["Title_name"].ToString();
                show.SimsTitleId = Convert.ToInt32(reader["Sims_title_id"].ToString());
                show.ProgramId = Convert.ToInt32(reader["Program_id"].ToString());
                show.Genre = reader["Genre_list"].ToString();
                show.ProgramName = reader["program_name"].ToString();
                show.ShowUrl = reader["ShowURL"].ToString();
                show.CssClass = reader["CSSCLASS"].ToString();
                shows.Add(show);
                i++;
            }
            reader.Close();
            reader.Dispose();
            return shows;
        }

        static public string SerializeToXML(List<ScheduledShow> shows)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<ScheduledShow>), new XmlRootAttribute("ScheduledShows"));
            //StringWriter stringWriter = new StringWriter();
            string xml;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8))
                {
                    serializer.Serialize(xmlTextWriter, shows);
                    using (MemoryStream memoryStream2 = (MemoryStream)xmlTextWriter.BaseStream)
                    {
                        xml = UTF8ByteArrayToString(memoryStream2.ToArray());
                    }
                }
            }

            return xml;
        }

        /// <summary>
        /// To convert a Byte Array of Unicode values (UTF-8 encoded) to a complete String.
        /// </summary>
        /// <param name="characters">Unicode Byte Array to be converted to String</param>
        /// <returns>String converted from Unicode Byte Array</returns>
        private static String UTF8ByteArrayToString(Byte[] characters)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            String constructedString = encoding.GetString(characters);
            return (constructedString);
        }
    }
}

ScheduledShow.cs

using System;
using System.Xml.Serialization;


namespace CommunityServer.Scheduler
{

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

        [XmlElement("AirTime")]
        public DateTime AirTime
        { get; set; }

        [XmlElement("StationId")]
        public int StationId
        { get; set; }

        [XmlElement("ScheduleRowId")]
        public int ScheduleRowId
        { get; set; }

        [XmlElement("StoryLine")]
        public string StoryLine
        { get; set; }

        [XmlElement("Title")]
        public string Title
        { get; set; }

        [XmlElement("ProgramId")]
        public int ProgramId
        { get; set; }

        [XmlElement("Genre")]
        public string Genre
        { get; set; }

        [XmlElement("ProgramName")]
        public string ProgramName
        { get; set; }

        [XmlElement("SimsTitleId")]
        public int SimsTitleId
        { get; set; }

        [XmlElement("ShowUrl")]
        public string ShowUrl
        { get; set; }

        [XmlElement("CssClass")]
        public string CssClass
        { get; set; }

    }
}

Output of the xml file

 <?xml version="1.0" encoding="utf-8"?>
<ScheduledShows xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <ScheduledShow>
        <AirTime xmlns="http://example.books.com">2009-09-17T10:20:00</AirTime>
        <StationId xmlns="http://example.books.com">770</StationId>
        <ScheduleRowId xmlns="http://example.books.com">17666100</ScheduleRowId>
        <StoryLine xmlns="http://example.books.com">When Dooley demonstrates his newest hobby, magic, Willa gets an idea.  A huge backyard magic show!  Starring the Great Doolini and his amazing disappearing elephant trick!  Unfortunately, Lou the elephant misunderstands and thinks Willa wants him to disappear for real.   In the middle of the show Willa must find Lou and apologize so he&amp;rsquo;ll reappear! / When the animals and Willa discover an egg in their backyard, their parental propriety  kicks in.   Especially when Dooley relates a factoid about young hatchlings imprinting on the first critter they see.   Willa&amp;rsquo;s critters vie for egg watching rights, so they can be first to be called Mama!  Or Poppa!</StoryLine>
        <Title xmlns="http://example.books.com">Disappearing Act / Great Eggspectations</Title>
        <ProgramId xmlns="http://example.books.com">2202</ProgramId>
        <Genre xmlns="http://example.books.com">Animated</Genre>
        <ProgramName xmlns="http://example.books.com">Willa's Wild Life</ProgramName>
        <SimsTitleId xmlns="http://example.books.com">68914</SimsTitleId>
        <ShowUrl xmlns="http://example.books.com">willas_wildlife</ShowUrl>
        <CssClass xmlns="http://example.books.com">none</CssClass>
    </ScheduledShow>
    <ScheduledShow>
        <AirTime xmlns="http://example.books.com">2009-09-17T10:45:00</AirTime>
        <StationId xmlns="http://example.books.com">770</StationId>
        <ScheduleRowId xmlns="http://example.books.com">17666105</ScheduleRowId>
        <StoryLine xmlns="http://example.books.com">It&amp;rsquo;s Club Day in Gloomsville. The gang splinter off to form clubs and prepare for the club&amp;rsquo;s appearance in the big Gloomsville parade.  Skull Boy forms the coolest club of all with some new jazzy skeletal friends that no one ever sees.  At first no one believes Skull Boy has these new friends since every time they want to meet them, they disappear.   When pressed for details, she admits she hasn&amp;rsquo;t met them yet &amp;ndash; they&amp;rsquo;re imaginary. </StoryLine>
        <Title xmlns="http://example.books.com">Skull Boys Don't Cry</Title>
        <ProgramId xmlns="http://example.books.com">1418</ProgramId>
        <Genre xmlns="http://example.books.com">Animated</Genre>
        <ProgramName xmlns="http://example.books.com">Ruby Gloom</ProgramName>
        <SimsTitleId xmlns="http://example.books.com">54297</SimsTitleId>
        <ShowUrl xmlns="http://example.books.com">rubygloom</ShowUrl>
        <CssClass xmlns="http://example.books.com">none</CssClass>
    </ScheduledShow>
    <ScheduledShow>
        <AirTime xmlns="http://example.books.com">2009-09-17T11:10:00</AirTime>
        <StationId xmlns="http://example.books.com">770</StationId>
        <ScheduleRowId xmlns="http://example.books.com">17666113</ScheduleRowId>
        <StoryLine xmlns="http://example.books.com">When Mad Margaret gets trapped in a jar she becomes a source of entertainment for Erky./Erky and Perky need a place to live and who better to find it for them than Frenzel.</StoryLine>
        <Title xmlns="http://example.books.com">Erky's Birthday / Location Location Location</Title>
        <ProgramId xmlns="http://example.books.com">1347</ProgramId>
        <Genre xmlns="http://example.books.com">Animated</Genre>
        <ProgramName xmlns="http://example.books.com">Erky Perky</ProgramName>
        <SimsTitleId xmlns="http://example.books.com">49009</SimsTitleId>
        <ShowUrl xmlns="http://example.books.com">erky_perky</ShowUrl>
        <CssClass xmlns="http://example.books.com">none</CssClass>
    </ScheduledShow>
    <ScheduledShow>
        <AirTime xmlns="http://example.books.com">2009-09-17T11:35:00</AirTime>
        <StationId xmlns="http://example.books.com">770</StationId>
        <ScheduleRowId xmlns="http://example.books.com">17666116</ScheduleRowId>
        <StoryLine xmlns="http://example.books.com">SYNOPSIS:The Joyco toy company has heard about George and his Zoopercar and they want to market it as their newest toy.  But George isn't interested in selling his prized mode of transportation.  Afterall, he and his Dad built it together and no one can take that special bond away from him.  But two Joyco toy employees, Barry and Steve, have other plans.  If George won't sell it to them, they will just have to take it, which they do.  But once their boss, Big Ed Easy finds out that George has be</StoryLine>
        <Title xmlns="http://example.books.com">ZOOPERCAR CAPER</Title>
        <ProgramId xmlns="http://example.books.com">311</ProgramId>
        <Genre xmlns="http://example.books.com" />
        <ProgramName xmlns="http://example.books.com">George Shrinks</ProgramName>
        <SimsTitleId xmlns="http://example.books.com">25371</SimsTitleId>
        <ShowUrl xmlns="http://example.books.com" />
        <CssClass xmlns="http://example.books.com">none</CssClass>
    </ScheduledShow>
    <ScheduledShow>
        <AirTime xmlns="http://example.books.com">2009-09-17T11:35:00</AirTime>
        <StationId xmlns="http://example.books.com">770</StationId>
        <ScheduleRowId xmlns="http://example.books.com">17666116</ScheduleRowId>
        <StoryLine xmlns="http://example.books.com">SYNOPSIS:The Joyco toy company has heard about George and his Zoopercar and they want to market it as their newest toy.  But George isn't interested in selling his prized mode of transportation.  Afterall, he and his Dad built it together and no one can take that special bond away from him.  But two Joyco toy employees, Barry and Steve, have other plans.  If George won't sell it to them, they will just have to take it, which they do.  But once their boss, Big Ed Easy finds out that George has be</StoryLine>
        <Title xmlns="http://example.books.com">ZOOPERCAR CAPER</Title>
        <ProgramId xmlns="http://example.books.com">311</ProgramId>
        <Genre xmlns="http://example.books.com" />
        <ProgramName xmlns="http://example.books.com">George Shrinks</ProgramName>
        <SimsTitleId xmlns="http://example.books.com">25371</SimsTitleId>
        <ShowUrl xmlns="http://example.books.com">george_shrinks</ShowUrl>
        <CssClass xmlns="http://example.books.com">none</CssClass>
    </ScheduledShow>
</ScheduledShows>
解决方案

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()FOR XML Serilization不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 04:04