取消种族歧视是行不通的
本文关键字:行不通 种族歧视 取消 | 更新日期: 2023-09-27 18:26:01
这是xml流:
<?xml version="1.0" encoding="utf-8" ?>
<historydetails>
<taskEvent>
<eventtype>Transitions</eventtype>
<historyevent>Task moved</historyevent>
<details>From 'Requested' to 'In Validation'</details>
<author>NAme</author>
<entrydate>01 Jul 13, 11:34</entrydate>
<historyid>2620</historyid>
</taskEvent>
<taskEvent>
<eventtype>Updates</eventtype>
<historyevent>Subtask marked done</historyevent>
<details>Subtask: visualise status and versions</details>
<author>NAme2</author>
<entrydate>21 Jun 13, 10:16</entrydate>
<historyid>2588</historyid>
</taskEvent>
</historydetails>
相应的类如下所示:
public class historydetails
{
[XmlElement("taskEvent")]
List<taskEvent> eventList = new List<taskEvent>();
}
public class taskEvent
{
string eventtype { get; set; }
string historyevent { get; set; }
string details { get; set; }
string author { get; set; }
string entrydate { get; set; }
string historyid { get; set; }
}
取消xml序列化的代码(字符串替换包含xml代码):
XmlSerializer deserializer = new XmlSerializer(typeof(historydetails));
object obj = obj = deserializer.Deserialize(stringToStream(replacement));
historydetails XmlData = (historydetails)obj;
字符串到流的方法
private MemoryStream stringToStream(string input)
{
byte[] byteArray = Encoding.ASCII.GetBytes(input);
MemoryStream stream = new MemoryStream(byteArray);
return stream;
}
我得到的结果如下:对象XmlData已生成,并且有一个taskEvents列表。问题出在列表本身:它是空的。。。
您必须使成员公开
public class historydetails
{
[XmlElement("taskEvent")]
public List<taskEvent> eventList = new List<taskEvent>();
}
public class taskEvent
{
public string eventtype { get; set; }
public string historyevent { get; set; }
public string details { get; set; }
public string author { get; set; }
public string entrydate { get; set; }
public string historyid { get; set; }
}
顺便说一句,为了将来参考(使用Visual Studio 2012或WebEssentials插件),基于一些示例XML内容数据创建类的最简单方法之一是将其复制到剪贴板中,然后使用内置的VS函数:EDIT->Paste Special->Past XML As classes到一个新的类文件中。
- 它为您遇到的错误留下了更少的空间
- 速度很快,几秒钟后你就可以上课了