- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试让我的 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
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);
}
}
}
预定显示.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; }
}
}
xml文件的输出
<?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&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&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&rsquo;s Club Day in Gloomsville. The gang splinter off to form clubs and prepare for the club&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&rsquo;t met them yet &ndash; they&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>
最佳答案
我在这里找到了问题的答案:
http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/4b228734-a209-445a-991c-0420b381ac93
我刚刚使用了 [XmlType("")]
并且成功了。
using System;
using System.Xml.Serialization;
namespace CommunityServer.Scheduler
{
[XmlType("ScheduledShowElement")]
public class ScheduledShow
{
...
}
}
关于c# - 用于 Xml 序列化的 XmlRoot() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1440845/
我在为 MacOSX 构建的独立包中添加 DMG 背景的自定义图标时遇到问题。我在项目的根目录中添加了一个包。正在从中加载自定义图标,但没有加载 DMG 背景图标。我正在使用 Java fx 2.2.
Qt for Symbian 和 Qt for MeeGo 有什么区别?我知道 Qt 是一个交叉编译平台。这是否意味着如果我使用来自 Qt 的库,完全相同的库可以在所有支持 Qt 的设备(例如 Sym
我正在尝试使用 C# .NET 3.5/4.0 务实地运行 SQL Server 数据库的备份。我已经找到了如何完成此操作,但是我似乎找不到用于备份的命名空间库。 我正在寻找 Microsoft.Sq
我最近在疯狂学习 Java,但我通常是一名 .NET 开发人员。 (所以请原谅我的新手问题。) 在 .Net 中,我可以在不使用 IIS 的情况下开发 ASP.Net 页面,因为它有一个简化的 Web
这post仅当打印命令中有字符串时才有用。现在我有大量的源代码,其中包含一条声明,例如 print milk,butter 应该格式化为 print(milk,butter) 用\n 捕获行尾并不成功
所以我的问题是: https://gist.github.com/panSarin/4a221a0923927115584a 当我保存这个表格时,我收到了标题中的错误 NoMethodError (u
如何让 Html5 音频在点击时播放声音? (ogg 用于 Firefox 等浏览器,mp3 用于 chrome 等浏览器) 到目前为止,我可以通过 onclick 更改为单个文件类型,但我无法像在普
如果it1和it2有什么区别? std::set s; auto it1 = std::inserter(s, s.begin()); auto it2 = std::inserter(s, s.en
4.0.0 com.amkit myapp SpringMVCFirst
我目前使用 Eclipse 作为其他语言的 IDE,而且我习惯于不必离开 IDE 做任何事情 - 但是我真的很难为纯 ECMAScript-262 找到相同或类似的设置。 澄清一下,我不是在寻找 DO
我想将带有字符串数组的C# 结构发送到C++ 函数,该函数接受void * 作为c# 结构和char** 作为c# 结构字符串数组成员。 我能够将结构发送到 c++ 函数,但问题是,无法从 c++ 函
我正在使用动态创建的链接: 我想为f:param附加自定义转换器,以从#{name}等中删除空格。 但是f:param中没有转换器
是否可以利用Redis为.NET创建后写或直写式缓存?理想情况下,透明的高速缓存是由单个进程写入的,并且支持从数据库加载丢失的数据,并每隔一段时间持久保存脏块? 我已经搜查了好几个小时,也许是goog
我正在通过bash执行命令的ssh脚本。 FILENAMES=( "export_production_20200604.tgz" "export_production_log_2020060
我需要一个正则表达式来出现 0 到 7 个字母或 0 到 7 个数字。 例如:匹配:1234、asdbs 不匹配:123456789、absbsafsfsf、asf12 我尝试了([a-zA-Z]{0
我有一个用于会计期间的表格,该表格具有期间结束和开始的开始日期和结束日期。我使用此表来确定何时发生服务交易以及何时在查询中收集收入,例如... SELECT p.PeriodID, p.FiscalY
我很难为只接受字符或数字的 Laravel 构建正则表达式验证。它是这样的: 你好<-好的 123 <- 好的 你好123 <-不行 我现在的正则表达式是这样的:[A-Za-z]|[0-9]。 reg
您实际上会在 Repeater 上使用 OnItemDataBound 做什么? 最佳答案 “此事件为您提供在客户端显示数据项之前访问数据项的最后机会。引发此事件后,数据项将被清空,不再可用。” ~
我有一个 fragment 工作正常的项目,我正在使用 jeremyfeinstein 的 actionbarsherlock 和滑动菜单, 一切正常,但是当我想自定义左侧抽屉列表单元格时,出现异常
最近几天,我似乎平均分配时间在构建我的第一个应用程序和在这里发布问题!! 这是我的第一个应用程序,也是我们的设计师完成的第一个应用程序。我试图满足他所做的事情的外观和感觉,但我认为他没有做适当的事情。
我是一名优秀的程序员,十分优秀!