Need your help in setting the xml attributes for XML deserialization.
This is my input xml:
<form>
<question id="QnA">
<answer>AnswerforA</answer>
</question>
<question id="QnB">
<answer>AnswerforB</answer>
</question>
<question id="QnC">
<answer>AnswerforC</answer>
</question>
</form>
The ids of each question element tag correspond to a class property and its value is the innertext of the corresponding answer element.
The .cs file will look like
public class Test
{
private string qnaAns;
private string qnbAns;
private string qncAns;
public string QnA
{
get{ return qnaAns;}
set{qnaAns = value;}
}
public string QnB
{
get{ return qnbAns;}
set{qnbAns = value;}
}
public string QnC
{
get{ return qncAns;}
set{qncAns = value;}
}
}
and I use the follwing code for deserialization
XmlSerializer ser = new XmlSerializer(typeof(Test));
XmlReader xr = new xmlReader(inputxml);
Test t = ser.Deserialize(xr) as Test;
Please let me know how to set the XML element/attribute for the Test class to achieve this.
Thanks for your time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…