您好我正在使用XML序列化程序从.NET中的Web服务反序列化传入的xml
我使用XSD.exe
创建了一个序列化类我有这个间歇性问题,有时XML没有正确反序列化,
在XML文件中有一个结果的根元素,它有一个子元素事务,这是多个事务元素的集合但是,有时在反序列化时只创建1,即使XML中存在多个,
因为它是断断续续的,我最初的想法是XML不同,但事实并非如此。
这是我的代码:
反序列化类
public partial class Result
{
private ResultTransaction[] transactionsField;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItem("Transaction")]
public ResultTransaction[] Transactions
{
get
{
return this.transactionsField;
}
set
{
this.transactionsField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class ResultTransaction
{
private ResultTransactionSequence sequenceField;
private ResultTransactionActivity activityField;
private System.DateTime issuedField;
private ResultTransactionUser userField;
private string notesField;
}
反序列化代码
StringReader rdr = new StringReader(xml);
XmlSerializer serializer = new XmlSerializer(typeof(Result));
Result res = (Result)serializer.Deserialize(rdr);
示例XML:
<Result>
<Transactions>
<Transaction>
<sequence>
<transactiontype>Customer</transactiontype>
</sequence>
<Customer>
</Customer>
</Transaction>
<Transaction>
<sequence>
<transactiontype>Customer</transactiontype>
</sequence>
<Customer>
</Customer>
</Transaction>
<Transactions>
</Result>
有谁知道为什么这会让我疯狂