此XML的幾個元素不會反序列化,但它也不會引發任何錯誤。無法反序列化此xml的所有元素
<?xml version="1.0" encoding="utf-8"?>
<TrialMWordsRecord xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyList>
<MWords>
<Id>0</Id>
<Name>ListMWords1</Name>
<Type>LIST</Type>
<MyOutput>true</MyOutput>
<WordsElements>
<Words>
<Name>ListMWords1</Name>
<Value>Apple</Value>
<Type>STRING</Type>
</Words>
<Words>
<Name>ListMWords1</Name>
<Value>Mango</Value>
<Type>STRING</Type>
</Words>
<Words>
<Name>ListMWords1</Name>
<Value>Chickoo</Value>
<Type>STRING</Type>
</Words>
</WordsElements>
</MWords>
<MWords>
<Id>1</Id>
<Type>RANDOM</Type>
<MyOutput>true</MyOutput>
<WordsElements>
<Name>Limit</Name>
<Value>3,8</Value>
<Type>NUMERIC</Type>
</WordsElements>
</MWords>
</TrialMWordsList>
</MyListRecord>
下面是我的課:
[Serializable()]
[XmlRootAttribute("MyListRecord")]
public class MyList
{
[XmlArray("MyList")]
public List<MWords> MWords
{
get;
set;
}
public static MyList Deserialize()
{
XmlSerializer deserializer = new XmlSerializer(typeof(MyList));
TextReader textReader = new StreamReader(Application.StartupPath + "\\MyList.xml");
MyList resultList = (MyList)deserializer.Deserialize(textReader);
textReader.Close();
return resultList;
}
}
[Serializable()]
public class MWords
{
public int Id
{
get;
set;
}
public MWordsType Type
{
get;
set;
}
public bool MyOutput
{
get;
set;
}
public string Requirement
{
get;
set;
}
[XmlArrayItem("WordsElements")]
public List<Words> WordList
{
get;
set;
}
public static MWords Deserialize()
{
XmlSerializer deserializer = new XmlSerializer(typeof(MWords));
TextReader textReader = new StreamReader(Application.StartupPath + "\\MWords.xml");
MWords mwords = (MWords)deserializer.Deserialize(textReader);
textReader.Close();
return mwords;
}
}
public class Words
{
public string Value
{
get;
set;
}
public TYPE Type
{
get;
set;
}
public string Name
{
get;
set;
}
}
現在,當我反序列化這個XML,如果類型是列表,詞表得到更新,例如這裏計數WordList將是3,但如果類型是RANDOM,WordList是0,實際上應該是1而不是0. 真的不知道可能是什麼原因。爲類型的隨機不<Words></Words>
包裹元素WordsElements
的
它給出了什麼異常? – user1291401 2014-11-04 08:15:14