unable to deserialize all elements of this xml



Few elements of this XML does not deserialize and but also it does not throw any errors also.



<?xml version="1.0" encoding="utf-8"?>
<TrialMWordsRecord xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY">
<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>


Below is my classes :


[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;
}


}


Now when i deserialize this xml, if Type is LiST the WordList gets updated eg. here count for WordList will be 3 but if Type is RANDOM WordList is 0 which should be actually 1 and not 0. Really don't know what coudl be the reason.


No comments:

Post a Comment